"""
Takoma Park MS
Jr-5
Contest 4
Nicholas Khil
"""
def isPrime(n,l):
    if n in l:
        return True;
    else:
        return False;
def isSquare(n,l):
    if n in l:
        return True;
    else:
        return False;
def isDivisible(m,n):
    if m%n == 0:
        return True;
    else:
        return False;
f = open("4jr_testdata.txt","r")
opInd = [1,2,3]
pInd = 4
numRolls = 5
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
squares = [9,16,25,36,49]
s1 = [6,11,16,21,26,34,39,44,49]
vm = ['v','v','h','h','h','h','v','h','h','h','h','v','h','h','h','h','v','h','h','h','h','v','v','v','v','h','v','v','v','v','h','h','h','h','v','h','h','h','h','v','h','h','h','h','v','h','h','h','h','v','v']

for line in f:
    opSpots = []
    b = list(52*"-")
    l = line.strip('\n').split()
    for i in range(len(l)):
        if i+1 in opInd:
            b[int(l[i])-1] = "X"
            opSpots.append(int(l[i]))
        if i+1 == pInd:
            b[int(l[i])-1] = "O"
            pos = int(l[i])
        if i+1 >= 5:
            if i+1 == numRolls:
                continue
            else:
                if pos + int(l[i]) > 52 or pos + int(l[i]) in opSpots:
                    continue
                elif pos + int(l[i]) == 52:
                    pos = "GAME OVER"
                    break
                #7
                elif isPrime(pos+int(l[i]),primes):
                    prevPos = pos
                    pos += int(l[i])
                    count = 0
                    while count < 6:
                        if pos + 1 in opSpots:
                           count = 6
                        else:
                           count += 1
                           pos += 1
                #8
                elif isSquare(pos+int(l[i]),squares):
                    prevPos = pos
                    pos += int(l[i])
                    count = 0
                    while count < 6:
                        if pos - 1 in opSpots:
                           count = 6
                        else:
                           count += 1
                           pos -= 1
                #9        
                else:
                    if i+1 >= 6:
                        case1 = 0
                        curRoll = l[i]
                        prevRoll = l[i-1]
                        for z in range(len(s1)):
                            if pos <= s1[z] and pos >= s1[z]-4 and pos+int(l[i]) >= s1[z]+2:
                                case1 = 1
                                break
                        if case1 == 1:
                            if isDivisible(pos+int(l[i]),int(l[i])) and pos+int(l[i]) not in opSpots:
                                pos += int(l[i])
                            elif isDivisible(pos+int(l[i])-1,int(l[i])) and pos+int(l[i])-1 not in opSpots and pos+int(l[i])-1 > pos:
                                pos += int(l[i])-1
                            elif isDivisible(pos+int(l[i])-2,int(l[i])) and pos+int(l[i])-2 not in opSpots and pos+int(l[i])-2 > pos:
                                pos += int(l[i])-2
                            elif isDivisible(pos+int(l[i])-3,int(l[i])) and pos+int(l[i])-3 not in opSpots and pos+int(l[i])-3 > pos:
                                pos += int(l[i])-3
                            elif isDivisible(pos+int(l[i])-4,int(l[i])) and pos+int(l[i])-4 not in opSpots and pos+int(l[i])-4 > pos:
                                pos += int(l[i])-4
                            elif isDivisible(pos+int(l[i])-5,int(l[i])) and pos+int(l[i])-5 not in opSpots and pos+int(l[i])-5 > pos:
                                pos += int(l[i])-5
                        else:
                            pos += int(l[i])
                           
                       
                           
                           
                   
    print(pos)