l=list(map(int,input().split()))

for i in range(5):

  if l[i]==0:

    print((i+1))

    break
l=list(map(int,input().split()))

for i in range(5):

  if l[i]!=i+1:

    print((i+1))
l = list(map(int, input().split()))
for i in range(5):
    if l[i] == 0:
        print((i + 1))
        break

l = list(map(int, input().split()))
for i in range(5):
    if l[i] != i + 1:
        print((i + 1))

-    if l[i] == 0: +    if l[i] != i + 1: -        break