/*Vaibhav Janardhan, ACSL Contest 4*/

import java.util.Scanner;

public class Patolli
{
    //Constructor; sets the positions for u and your opponents spaces
    Patolli(int z, int a, int b, int c){
	   board[z] = true;
	   board[a] = true;
	   board[b] = true;
	   board[c] = true;
	   mypos = c;
    }
	//Your position
	private int mypos;
	//An array that defines the Patolli board, and it keps track of occupation
	private boolean board [] = new boolean [53];
	//computes what  moves you will be doing
	public int move(int f){
	   //checks to make sure that the move doesn't take you over 52
	   if (mypos + f <= 52){
	       //Checks to see if the move makes you land on a occupied space
	        if (board[mypos + f] == false){
	               mypos = mypos + f;
	        }
	       //Portrays the use of rule 7
	        if (isPrime(mypos)){
	            //moves to furthest possible position
	            mypos = goTo(mypos, mypos + 6);
	            return mypos;
	        }
	       //POrtrays the use of rule 8
	        if (isSquare(mypos)){
	            mypos = goTo(mypos, mypos - 6);
	            return mypos;
	        }     
	        //Rule 9
	        mypos = ruleNine(mypos - f, f);
	        return mypos;
	   }
	   return mypos;
	}
	//Tells you if you're on a square
	private boolean isSquare(int h){
	   if (mypos == 9||mypos == 16|| mypos == 25||mypos == 36||mypos == 49){
	        return true;
	   }
	   return false;
	}
	//Tells you if you're on a prime number
	private boolean isPrime(int g){
	    switch(g){
	        case 2:
	        case 3: 
	        case 5:
	        case 7:
	        return true;
	        default:
	        if ((g/3)*3 == g|| (g/2)*2 == g||(g/5)*5 == g||(g/7)*7 == g){
	            return false;
	        }
	        return true;
	    }
	}
	
	private int goTo(int start, int end){
	    if (start > end){
	        int i = start;
	        for (; i >= end; i--){
	            if (board[i]){
	                return i + 1;
	            }
	        }
	        return end;
	    }
	    for (int i = start; i <= end; i++){
	        if (board[i]){
	            return i - 1;
	        }
	    }
	    return end;
	}
	
	private int ruleNine(int start, int roll){
	    if (start < 7 && start + roll > 7||start < 12 && start + roll > 12||start < 17 && start + roll > 17||start < 22 && start + roll > 22||start < 35 && start + roll > 35||start < 40 && start + roll > 40||start < 45 && start + roll > 45||start < 50 && start + roll > 50||start < 27 && start + roll > 27){
	        for (int i = start + roll; i >= start; i--){
	            if (i % roll == 0){
	                if (board[i]){
	                    return start;
	                }
	                else{
	                    return i;
	                }
	            }
	        }
	    }
	    return start + roll;
	}
	
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		String y = x.next();
	    int z = Integer.parseInt(y);
	    y = x.next();
	    int a = Integer.parseInt(y);
	    y = x.next();
	    int b = Integer.parseInt(y);
	    y = x.next();
	    int c = Integer.parseInt(y);
	    //Creates Patolli object using inputs
	    Patolli pat = new Patolli(z, a, b, c);
	    y = x.next();
	    //Figures out how many moves there are
	    int d = Integer.parseInt(y);
	    int e = 0;
	    //Makes the number of moves using d
	    for (;d>0; d--){
	        y = x.next();
	        e = Integer.parseInt(y);
	        e = pat.move(e);
	        //System.out.println(e);
	        if (e == 52){
	            System.out.println("GAME OVER");
	            return;
	        }
	    }
	    System.out.println(e);
	}
}