import numpy as np from scipy.optimize import linprog u,v,w,x,y = map(int,input().split()) c = [-1, -1, -1, -1, -1] A = [[1, 0, 0, 1, 1], [1, 1, 0, 0, 1], [1, 1, 1, 0, 0], [0, 1, 1, 1, 0], [0, 0, 1, 1, 1]] b = [u, v, w, x, y] ans = linprog(c, A_ub=A, b_ub=b, method='revised simplex') print(int(-ans.fun + 0.001))