# Arup Guha
# 2/24/2024
# Solution to SER D2 Problem H: Triple Sevens

# Get # of options.
n = int(input())

# Our accumulator.
cnt = 0

# Go through each dial.
for i in range(3):

    # Store options in list.
    nums = [int(x) for x in input().split()]

    # See if there's a 7.
    if 7 in nums:
        cnt+=1

# Output accordingly.
if cnt == 3:
    print(777)
else:
    print(0)
