p = 0
while p == 1:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
x = int(input())
p = 0
if a == 0:
print(a)
p = 1
if b == 0:
print(a + b)
p = 1
if c == 0:
print(a + b + c)
p = 1
if d == 0:
print(a + b + c + d)
p = 1
if x == 0:
print( a + b + c + d)
p = 1