import math


def iPS(x):
    sr = math.sqrt(x)
    return ((sr - math.floor(sr)) == 0)


def nop(string):
    punctuations = '''!()-[]{};:'"\,<>./?@#$ %^*_~'''
    for x in string.lower():
        if x in punctuations:
            string = string.replace(x, "")
    return string


def isP(n):
    if (n <= 1):
        return False
    if (n <= 3):
        return True
    if (n % 2 == 0 or n % 3 == 0):
        return False
    i = 5
    while (i * i <= n):
        if (n % i == 0 or n % (i + 2) == 0):
            return False
        i = i + 6
    return True


#Define Index
list2 = [
    "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"
]
#define inputs
s = str(input())
list3 = list(map(int, s.split()))
op = [list3[0], list3[1], list3[2]]
stt = list3[3]
end = ""
#7
list4 = []
#8
list5 = []
#9
list6 = []
K = []
list7 =[]




for j in range(list3[4]):
  end = (int(stt) + int(list3[j+5]))
  #4
  if end in op:
    end = int(stt)
  #6
  elif end == 52:
    end = 52 
    break
  elif end > 52:
    end = int(stt)
  else:
    #7
    if isP(int(end)) == True: 
      if end < list3[0] <= end + 6 or end < list3[1] <= end + 6 or end < list3[2] <= end + 6:
        if end < list3[0] <= end + 6:
          list4.append(list3[0])
        if end < list3[1] <= end + 6:
          list4.append(list3[1])
        if end < list3[2] <= end + 6:
          list4.append(list3[2])
        stt = end
        end = min(list4) - 1
        list4 = []
      else:
        stt = end
        end = end + 6
        #8
    elif iPS(int(end)) == True and end > 4:
      if end - 6 <= list3[0] < end or end - 6 <= list3[1] < end or end - 6 <= list3[2] < end:
        if (end - 6) <= list3[0] < end:
          list5.append(list3[0])
        if (end - 6) <= list3[1] < end:
          list5.append(list3[1])
        if (end - 6) <= list3[2] < end:
          list5.append(list3[2])
        stt = end 
        end = min(list5) + 1
        list5 = []
      else:
        stt = end 
        end = end - 6
    #9
    else:
      for i in range(int(end) - int(stt)):
        list6.append(list2[int(stt) - 1 + i])
        c = str(nop(str(list6)))
        list7.append(c)
        if "hv" in list7[-1]:
          for i in range(int(stt) + 1, int(end) + 1):
            if i % list3[j+5] == 0 and i != list3[0] and i!= list3[1] and i!=list3[2]:
              K.append(i)
              stt = end
              end = nop(str(K))
            if i % list3[j+5] == 0 and i == list3[0] or i % list3[j+5] == 0 and i == list3[1] or i % list3[j+5] == 0 and i == list3[2]:
              end = int(end)-list3[j+5]
        else:
          end = end
      list7 = []
      list6 = []
      c = ""
      K = []
    stt = end

if end == 52:
  print("GAME OVER")
else:
  print(end)