/**

 * Dan Vogel

 * Marriotts Ridge High School

 * Contest # 3

 * Division - Junior

 * March 12, 2010

 */

 

 

 

 

import java.util.Scanner;

import java.io.IOException;

import java.io.File;

 

public class SenetClient

{

 

           

            public static void main(String[] args) throws IOException

            {

                       

                        String pathtoFile = "F:";

            //            String pathtoFile = "Z:/CS I/Senet";

                        File inFile = new File(pathtoFile, "senetJr.txt");

            //            File inFile = new File(pathtoFile, "senetDatter");

                        Scanner dataIn = new Scanner(inFile);

                        String[]numbers = new String[40];

                        int scan, black = 0, white = 0, arraysize;

                        int fbp = 0;

                        int h;

                       

                       

            for(int q = 0;q < 5; q++)

            {

                        int blackpieces = dataIn.nextInt();

                       

                        for(h = 0; h < 40; h++)

                        {

                                    numbers[h] = "-";

                                   

                                   

                        }

                       

                       

                        for(scan = 1; scan <= blackpieces; scan ++)

                        {

                                   

                                    black = dataIn.nextInt();

                                    if(scan == 1)

                                    {

                                     fbp = black;

                        //            numbers[black];

                                    }

                                   

                                   

                                    numbers[black] = "B";

                                   

                       

           

                        }

                       

                       

                        int whitepieces = dataIn.nextInt();

                       

                        for(scan = 1; scan <= whitepieces; scan ++)

                        {

                                   

                                    white = dataIn.nextInt();

                                   

                                    if(scan == 1)

                                    {

                                    int fwp = white;

                                    }

                                   

                                    numbers[white] = "W";

                       

                       

                        numbers[white] = "W";

                        }

                        int move;

                        move = dataIn.nextInt();

                       

                        int total = fbp + move;

                       

                        if(fbp < 26 && total >= 26)

                        {

                                    total = 26;

                                    System.out.println(total);

                        }

                       

                        else if(numbers[total]==("B"))

                        {

                                    System.out.println("CANNOT MOVE");

                        }

                       

                       

                        else if(fbp ==29 && move ==2)

                        {

                                    System.out.println("DONE");

                        }

                       

                        else if(fbp == 28 && move ==3)

                        {

                                    System.out.println("DONE");

                        }

                       

                        else if((fbp == 30 && move ==1) || (fbp == 27 && move == 4) ||(fbp == 26 && move ==5))

                        {

                                    System.out.println("DONE");

                        }

                       

                        else if(fbp == 26 && move ==1)

                        {

                                    if(numbers[15]!=("B"))

                                                            {

                                                total = 15;

                                                            }

                                    else

                                                {

                                                total = 27;

                                                }

                                    System.out.println(total);

                        }

                       

                        else if(total > 31)

                        {

                                    System.out.println("CANNOT MOVE");

                        }

                        else

                                    System.out.println(total);

                       

                       

                       

                       

                       

                        for(h = 0; h < 31; h++)

                        {

                                   

                       

                        }

                       

                       

                       

                       

                       

                       

                       

                       

                       

                       

 

                       

                       

                       

                       

                       

}}}