start_number = int(input())

result = 0

while result < start_number:
    number = int(input())
    result += number
else:
    print(result)



start_number = int(input())

result = 0

while result < start_number:
    number = int(input())
    result += number
else:
    print(result)


