{
TASK:crazy
LANG:Pascal
}

program crazy;
uses module;
 var x,y:longint;
     br:boolean;
     simple:array[1..1000] of boolean;

Function Nod(a,b:longint):longint;
 begin
  while a<>b do
   if a>b then a:=a-b else b:=b-a;
  nod:=a;
 end;

Procedure init;
var i,j:longint;
begin
 simple[1]:=false;
 for i:=2 to 1000 do simple[i]:=true;
 for i:=2 to 500 do if simple[i] then begin
  j:=i*i;
  while j<=1000 do begin
   simple[j]:=false; j:=j+i;
  end;
 end;
end;

Function del(a:longint):longint;
var i:longint;
begin
 i:=0;
 for i:=3 to a div 2 do
  if (nod(a,i)<>1) and (not simple[i+1]) then begin
   del:=i; break;
  end;
end;


Function prdel(a,l:longint):longint;
var i,s,s1:longint;
begin
 s:=0; s1:=0;
 for i:=l to a div 2 do
  if (simple[i]) and (a mod i =0) then begin
   if (l=2) or ((l=3) and (simple[i+2])) then begin s1:=i;  break; end;
   if s=0 then s:=i;
  end;
 if s=0 then s:=del(a);
 prdel:=s;
 if s1<>0 then prdel:=s1;
end;

Begin
 init;
 br:=false;
 repeat
  getnum(x,y);
  if (not simple[x]) and simple[x+1] and (not simple[y]) then begin setnum(x+1,prdel(y,2)); halt(0); end;
  if (not simple[y]) and simple[y+1] and (not simple[x]) then begin setnum(prdel(x,2),y+1); halt(0); end;
  if x=2 then begin setnum(x+1,prdel(y,2));  halt(0); end;
  if y=2 then begin setnum(prdel(x,2),y+1);  halt(0); end;
  if simple[x] then setnum(x+1,prdel(y,3));
  if simple[y] then setnum(prdel(x,3),y+1);
  if (not simple[x]) and (not simple[y]) then setnum(del(x),y+1);
 until br;
End.
