/*
TASK:crazy
LANG:C
*/

#include <stdio.h>
#include <string.h>
#include "module.h"

#define MAXN            750

long x,y;
int simple[MAXN];
int brs;
int brsmp[MAXN];
short comsmp[MAXN][MAXN];
//int brconn[MAXN][MAXN];
int smsmp[MAXN];
int possit[MAXN][MAXN][2];
short tail[MAXN*MAXN*2][3];
int tput,tget;
short depth[MAXN][MAXN][2][3];
short winning[MAXN][MAXN][2];
long maxn;

void init()
{
  memset(brsmp,0,MAXN*sizeof(int));
  memset(smsmp,0,MAXN*sizeof(int));
  //memset(brconn,0,MAXN*MAXN*sizeof(int));
  memset(possit,0,2*MAXN*MAXN*sizeof(int));
  memset(depth,-1,2*3*MAXN*MAXN*sizeof(short));
//  memset(winning,1,2*MAXN*MAXN*sizeof(short));
}

int NOD(int a, int b)
{
  int tmp;

  while(b!=0)
  {
    tmp = b;
    b = a%b;
    a = tmp;
  }

  return a;
}

void CalcFor(int cur1,int cur2, int curp,int na,int nb, int nc)
{
  int i2;
  int check;

  if(na==8 && nb==8)
  {
    na++;
    na--;
  }

  check = 0;

  if(winning[na][nb][nc]==0)
  {
    check = 1;
    depth[na][nb][nc][0]=-1;
    winning[na][nb][nc] = 1;
  }

      if(na==9 && nb==4)
      {
        na++;
        na--;
      }

      if(depth[na][nb][nc][0]==-1 || depth[na][nb][nc][0]>depth[cur1][cur2][curp][0]+1)
      {
        depth[na][nb][nc][0] = depth[cur1][cur2][curp][0]+1;
        depth[na][nb][nc][1] = cur1;
        depth[na][nb][nc][2] = cur2;
      }


      if(check)
      {
        for(i2=0;i2<brsmp[na];i2++)
        {
          possit[comsmp[na][i2]][nb-1][1-nc]--;
          if(possit[comsmp[na][i2]][nb-1][1-nc]==0)
          {
            tail[tput][0] = comsmp[na][i2];
            tail[tput][1] = nb-1;
            tail[tput][2] = 1-nc;
            tput++;

            if(!winning[comsmp[na][i2]][nb-1][1-nc])
              if(depth[comsmp[na][i2]][nb-1][1-nc][0]==-1 || depth[comsmp[na][i2]][nb-1][1-nc][0]<depth[na][nb][nc][0]+1)
              {
                depth[comsmp[na][i2]][nb-1][1-nc][0] = depth[na][nb][nc][0]+1;
                depth[comsmp[na][i2]][nb-1][1-nc][1] = na;
                depth[comsmp[na][i2]][nb-1][1-nc][2] = nb;
              }
            
          }
        }

        for(i2=0;i2<brsmp[nb];i2++)
        {
          possit[na-1][comsmp[nb][i2]][1-nc]--;
          if(possit[na-1][comsmp[nb][i2]][1-nc]==0)
          {
            tail[tput][0] = na-1;
            tail[tput][1] = comsmp[nb][i2];
            tail[tput][2] = 1-nc;
            tput++;
            
            if(!winning[na-1][comsmp[nb][i2]][1-nc])
              if(depth[na-1][comsmp[nb][i2]][1-nc][0]==-1 || depth[na-1][comsmp[nb][i2]][1-nc][0]<depth[na][nb][nc][0]+1)
              {
                depth[na-1][comsmp[nb][i2]][1-nc][0] = depth[na][nb][nc][0]+1;
                depth[na-1][comsmp[nb][i2]][1-nc][1] = na;
                depth[na-1][comsmp[nb][i2]][1-nc][2] = nb;
              }
              
          }
        }
        
      }

}

void playgame()
{

  while(1)
  {
    printf("his: %d %d\n",x,y);
    printf("my: %d %d\n",depth[x][y][0][1],depth[x][y][0][2]);
    setnum(depth[x][y][0][1],depth[x][y][0][2]);
    getnum(&x,&y);    
  }
}

void solve()
{
  int i,i2;
  int check;
  int cur1,cur2,curp;
  int na,nb,nc;

  brs = 0;

  getnum(&x,&y);
  maxn = x;
  if(x<y)
    maxn = y;

  maxn*=1.5;
  if(maxn>MAXN)
    maxn = MAXN;

  for(i=2;i<maxn;i++)
  {
    check = 1;
  
    for(i2=2;i2*i2<=i;i2++)
      if((i%i2)==0)
      {
        check = 0;
        break;
      }

    if(check)
      simple[brs++] = i;
  }

  for(i=2;i<maxn;i++)
    for(i2=i+1;i2<maxn;i2++)
      if(NOD(i2,i)>1)
      {
        comsmp[i][brsmp[i]++] = i2;
        smsmp[i2]++;
      }

  for(i=2;i<maxn;i++)
    for(i2=2;i2<maxn;i2++)
    {
      possit[i][i2][0] = smsmp[i]+smsmp[i2];
      possit[i][i2][1] = smsmp[i]+smsmp[i2];
    }

  tput = tget = 0;

  for(i=0;i<brs;i++)
    for(i2=0;i2<brs;i2++)
    {
      tail[tput][0] = simple[i];
      tail[tput][1] = simple[i2];
      tail[tput][2] = 0;
      tput++;
      tail[tput][0] = simple[i];
      tail[tput][1] = simple[i2];
      tail[tput][2] = 1;
      tput++;
      depth[simple[i]][simple[i2]][0][0] = 0;
      depth[simple[i]][simple[i2]][1][0] = 0;
    }

  while(tput>tget)
  {
    cur1 = tail[tget][0];
    cur2 = tail[tget][1];
    curp = tail[tget][2];
    tget++;

    if(cur1==9 && cur2==4)
    {
      cur1++;
      cur1--;
    }

    for(i=0;i<brsmp[cur1];i++)
    {
      na = comsmp[cur1][i];
      nb = cur2-1;
      nc = 1-curp;
      
      if(na>1 && nb>1)
        CalcFor(cur1,cur2,curp,na,nb,nc);

/*      if(depth[na][nb][nc][0]==-1)
      {
        for(i2=0;i2<brsmp[na];i2++)
        {
          possit[comsmp[na][i2]][nb+1][1-nc]--;
          if(possit[comsmp[na][i2]][nb+1][1-nc]==0)
          {          
            tail[tput][0] = comsmp[na][i2];
            tail[tput][1] = nb-1;
            tail[tput][2] = 1-nc;
            tput++;
            
          }
        }

        for(i2=0;i2<brsmp[nb];i2++)
        {
          possit[na+1][comsmp[nb][i2]][1-nc]--;
          if(possit[na+1][comsmp[nb][i2]][1-nc]==0)
          {
            tail[tput][0] = na-1;
            tail[tput][1] = comsmp[nb][i2];
            tail[tput][2] = 1-nc;
            tput++;
          }
        }
        
      }

      if(na==9 && nb==4)
      {
        na++;
        na--;
      }

      if(depth[na][nb][nc][0]==-1 || depth[na][nb][nc][0]>depth[cur1][cur2][curp][0]+1)
      {
        depth[na][nb][nc][0] = depth[cur1][cur2][curp][0]+1;
        depth[na][nb][nc][1] = cur1;
        depth[na][nb][nc][2] = cur2;
      }*/

///////////////////////////////////////////

      na = cur1-1;
      nb = comsmp[cur2][i];
      nc = 1-curp;

      if(na>1 && nb>1)
        CalcFor(cur1,cur2,curp,na,nb,nc);

/*      if(depth[na][nb][nc][0]==-1)
      {
        for(i2=0;i2<brsmp[na];i2++)
        {
          possit[comsmp[na][i2]][nb+1][1-nc]--;
          if(possit[comsmp[na][i2]][nb+1][1-nc]==0)
          {
            depth[
            tail[tput][0] = comsmp[na][i2];
            tail[tput][1] = nb-1;
            tail[tput][2] = 1-nc;
            tput++;
          }
        }

        for(i2=0;i2<brsmp[nb];i2++)
        {
          possit[na+1][comsmp[nb][i2]][1-nc]--;
          if(possit[na+1][comsmp[nb][i2]][1-nc]==0)
          {
            tail[tput][0] = na-1;
            tail[tput][1] = comsmp[nb][i2];
            tail[tput][2] = 1-nc;
            tput++;
          }
        }
        
      }

      if(depth[na][nb][nc][0]==-1 || depth[na][nb][nc][0]>depth[cur1][cur2][curp][0]+1)
      {
        depth[na][nb][nc][0] = depth[cur1][cur2][curp][0]+1;
        depth[na][nb][nc][1] = cur1;
        depth[na][nb][nc][2] = cur2;
      }*/
    }
  }

  playgame();
}

int main()
{
  init();
  solve();


  return 0;
}

