import sys
def maxidx(input):
mmax = [None, 0]
for i in range(len(input)):
if input[i] > mmax[1]: mmax = [i, input[i]]
return mmax[0]
def doit(input):
banks = list(map(int,input.split()))
size = len(banks)
steps = 1
seen = {}
step_seen= {}
while True:
i = maxidx(banks)
m = banks[i]
item = int((m + size -1) / size)
last = m - (item * (size - 1))
banks[i] = 0
j = 1
while m > 0:
banks[(i+j)%size] += 1
m -= 1
j += 1
if str(banks) in seen:
break
seen[str(banks)] = True
step_seen[str(banks)] = steps
steps += 1
return "%d" % (steps - step_seen[str(banks)])
input = sys.stdin.read()
print(doit(input))