import sys import numpy as np import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines a, b, c, d, e = map(int, read().split()) A = np.array([ [1,0,0,0,0], [0,1,0,0,0], [0,0,1,0,0], [0,0,0,1,0], [0,0,0,0,1], [1,1,0,0,1], [1,1,1,0,0], [0,1,1,1,0], [0,0,1,1,1], [1,0,0,1,1], ], np.int64) v = np.array([0,0,0,0,0,a,b,c,d,e]) cand = [] for s in itertools.combinations(range(10), 5): A1 = np.concatenate([A[i] for i in s]).reshape(5,5) v1 = np.array([v[i] for i in s]) D = np.linalg.det(A1) if D == 0.0: continue x = np.linalg.solve(A1, v1) if np.any(x < -2): continue cand.append(x.astype(np.int64)) ans = 0 nums = (a,b,c,d,e) for x in cand: for eps in itertools.product(range(-1,2), repeat=5): y = x + np.array(eps) if np.any(y < 0): continue ok = True for i in range(5): if y[i] + y[(i-1)%5] + y[(i+1)%5] > nums[i]: ok = False break if ok: ans = max(ans, y.sum()) print(ans)