import numpy as np from scipy.optimize import linprog c = [-1,-1,-1,-1,-1] a_ub = [[1,1,1,0,0], [0,1,1,1,0], [0,0,1,1,1], [1,0,0,1,1], [1,1,0,0,1]] b_ub = list(map(int, input().split())) res = linprog(c, A_ub=a_ub, b_ub=b_ub, method='revised simplex') d = list(map(lambda x:int(round(x,0)), res.x)) rem = list(b_ub - a_ub @ np.array(d)) print(sum(d) + sorted(rem)[2])