a = input()
l = a.split(" ")
blocked = l[0:3]
for yeet in range(len(blocked)):
  blocked[yeet] = int(blocked[yeet])
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
rolls = l[5:len(l)]
for wheat in range(len(rolls)):
  rolls[wheat] = int(rolls[wheat])
squares = [9,16,25,36,49]
position = int(l[3])
HV = False
for x in range(len(rolls)):
  HV = False
  if position + rolls[x] <= 52:
    if position + rolls[x] not in blocked:
      if position + rolls[x] in primes:            #prime movement
        position += rolls[x]
        y = 1
        while y != 7:
          if position + 1 not in blocked:
            position += 1
          else:
            y = 6
          y += 1
      elif position + rolls[x] in squares:    #square movement
        position += rolls[x]
        z = 1
        while z != 7:
          if position - 1 not in blocked:
            position = position - 1
          else:
            z = 6
          z += 1
        if position < 1:
          position = 1
      else:                                   #non square/prime movement
        if position + rolls[x] not in [1,4]:
          if position > 45 and position + rolls[x] > 50:
            HV = True
          elif position > 40 and position + rolls[x] > 45:
            HV = True
          elif position > 35 and position < 40 and position + rolls[x] > 40:
            HV = True
          elif position > 30 and position < 35 and position + rolls[x] > 35:
            HV = True
          elif position == 26 and position + rolls[x] >27:
            HV = True
          elif position < 27 and position + rolls[x] > 27:
            HV = True
          elif position > 17 and position < 22 and position + rolls[x] > 22:
            HV = True
          elif position > 12 and position< 17 and position + rolls[x] > 17:
            HV = True
          elif position > 7 and position< 12 and position + rolls[x] > 12:
            HV = True
          elif position > 2 and position < 7 and position + rolls[x] > 7:
            HV = True
          else:
            position = position + rolls[x]
          if HV == True:
            if (position//rolls[x] + 1) * rolls[x] not in blocked:
              if (position//rolls[x] + 1) * rolls[x] <= 52:
                position = (position//rolls[x] + 1) * rolls[x]
        else:
          position += rolls[x]
if position == 52:
  print('GAME OVER')
else:
  print(position)