prime = [2,3,5,7,11,13,17,19,23,29,31,37,39,41,47]
square = [9,16,25,36,49]
limits = [[6, 8], [11, 13], [16,18],[21, 23], [26,28], [34,36], [39,41], [44,46], [49, 51]]
occupiedList = [0,0,0]

def occupied(i):
    if i in occupiedList:
        return True
    else:
        return False

def rule7(stPos, diceValue):
    block=False
    tryPos = stPos+diceValue
    for k in occupiedList:
        if k>tryPos and k<=tryPos + 6:
            tryPos = k-1
            block=True
            break

    if not block:
        tryPos = tryPos + 6
    return tryPos            
    
def rule8(stPos, diceValue):
    block = False
    tryPos = stPos+diceValue
    for k in occupiedList[::-1]:
        if k>=tryPos - 6 and k=limit[1]:
         flag = True
         break

    if flag:
        testPos = tryPos//diceValue * diceValue

        if (testPos<=stPos):
            tryPos = stPos
        else:
            if not occupied(testPos):
                tryPos = testPos
            else:
                while occupied(testPos) and testPos>stPos:
                    testPos = testPos - diceValue

                if testPos < stPos:
                    tryPos = stPos
                else:
                    tryPos = testPos
        
    return tryPos


def move(stPos, diceValue):
    newPos = stPos+diceValue

    if occupied(newPos) or (newPos > 52):
        newPos = stPos
    elif newPos == 52:
        newPos = 0
    elif newPos in prime:
        newPos = rule7(stPos, diceValue)
    elif newPos in square:
        newPos = rule8(stPos, diceValue)
    else:
        newPos = rule9(stPos, diceValue)

    return newPos 


data=[]
#print("Please input 5 sets of data:")
for i in range(5):
    data.append(input())

for i in range(5):
    nums = data[i].split(' ')
    occupiedList[0] = int(nums[0])
    occupiedList[1] = int(nums[1])
    occupiedList[2] = int(nums[2])
    pos = int(nums[3])
    r = int(nums[4])
    for step in nums[5:5+int(r)]:
        pos = move(pos, int(step))
        if pos == 0:
            break

    if pos == 0:
        print('GAME OVER')
    else:
        print(pos)