{
TASK:crazy
LANG:Pascal
}
program crazy;
uses module;
type
  list = array[1..150] of longint;

var
 x,y,x1,y1,n1,n2,n3 : LongInt;
 list1,list2,list3 : list;

procedure del(num : LongInt;var dels : list;var n : LongInt);
var
 i,j : integer;

begin

 n := 0;
 for i := 2 to (num div 2) do
   if num mod i = 0 then
   begin

     inc(n);
     dels[n] := i;
     for j := 1 to n-1 do
       if i mod dels[j] = 0 then
       begin
         dec(n);
         break;
       end;

   end;

end;
function next(num : LongInt) : LongInt;
var
 i : integer;

begin

  for i := 3 to num - 1 do
    if (num mod i = 0) and (i mod 2 = 0) then
      begin
        next := i;
        exit;
      end;

  next := 2;

end;
begin

  getnum(x,y);

  del(x,list1,n1);
  del(y,list2,n2);

    if n1 = 0 then
    begin

      x1 := x + 1;

      if (list2[1] = 2) then
        if n2 > 1 then
          y1 := list2[2]
        else if x1 <> 3 then
          y1 := next(y)
        else
          y1 := 2
      else
        y1 := list2[2];

    end
    else if n2 = 0 then
    begin

      y1 := y + 1;

      if (list1[1] = 2) then
        if n1 > 1 then
          x1 := list1[2]
        else if y1 <> 3 then
          x1 := next(x)
        else
          x1 := 2

      else
        x1 := list1[1];

    end
    else
    begin

      del(x+1,list3,n3);
      if n3 = 0 then
      begin
        x1 := x + 1;
        y1 := list2[1];
      end
      else
      begin

        del(y+1,list3,n3);

        if n3 = 0 then
        begin
          x1 := list1[1];
          y1 := y + 1;
        end
        else
        begin

          if list1[1] <> 2 then
            x1 := list1[1]
          else if n1 > 1 then
            x1 := list1[2]
          else
            x1 := next(x);

          y1 := y + 1;

        end;

      end;

    end;

  setnum(x1,y1);

end.