Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Print a single integer, denoting the minimum possible height of the tallest tower.

NoteIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.

uses Math;
type mass=array['A'..'Z'] of int64;
Var res,mn,a,b,c,d,x,y,n,k,ans,u,l,b1,r,a1:int64;
    m:mass;
    i,j,z:longint;
    s:string;
begin
//  assign(input,'input.txt');assign(output,'output.txt');
  readln(a,b);
  for i:=1 to 10000000 do
     if (i mod 2<>0) and (i mod 3<>0)
     then continue
     else Begin
             c:=a-(i div 2-i div 6);
             d:=b-(i div 3-i div 6);
             if (c<=0) and (d<=0)
             then begin
                     res:=i;
                     break;
                  end;
             if (c<=0)
             then if i div 3>=b
                  then Begin
                          res:=i;
                          break;
                       end
                  else continue;
             if (d<=0)
             then if i div 2>=a
                  then Begin
                          res:=i;
                          break;
                       end
                  else continue;
             if (i div 6>=c+d)
             then Begin
                     res:=i;
                     break;
                  end;
          end;
  writeln(res);
end.

var
n, m, i, max: integer;
begin
read(n, m);
for i:= 1 to 10000000 do
begin
if (i mod 6 = 0)  then
if (n <= m) and (m <> 0) then begin dec(m); max:= i; continue; end
else if n <> 0 then begin dec(n); max:= i; continue; end;
if (i mod 2 = 0) and (n >= 1) then begin dec(n); max:= i; continue; end;
if (i mod 3 = 0) and (m >= 1) then begin dec(m); max:= i; end;
end;
writeln(max);
end.

program cf_626C;
uses math;
var n,m,i,a1,b1,k1:longint;
begin
readln(n,m);
for i:=1 to 10000000 do
        begin
        if (i mod 6=0) then k1:=k1+1
        else if (i mod 2=0) then a1:=a1+1
        else if (i mod 3=0) then b1:=b1+1;
        if (k1-max(0,n-a1)-max(0,m-b1))=0 then
                begin
                writeln(i);
                break;
                end;
        end;
end.

var
 l,r,c,k1,k2,n1,m1,i,j,n,m,k,t,x:longint;
begin
 readln(n,m);
 l:=1;r:=10000000;
 while l<r do
 begin
  c:=(l+r)shr 1;
  k1:=c div 2-c div 6;
  k2:=c div 3-c div 6;
  if n-k1<0 then n1:=0 else n1:=n-k1;
  if m-k2<0 then m1:=0 else m1:=m-k2;
  if n1+m1<=c div 6 then r:=c else l:=c+1;
 end;
 writeln(l);
end.

var n,m,s1,s2,s:longint;
begin
 read(n);
 read(m);
 s1:=n*2;
 s2:=m*3;
 if s1<s2 then s:=s1
          else s:=s2;
 s:=s div 6;
 while s>0 do
  begin
   if s1<=s2 then
    begin
     dec(s);
     s1:=s1+2;
     if (s1<=s2)and(s1 mod 6=0) then
      inc(s);
    end else
    begin
     dec(s);
     s2:=s2+3;
    if (s2<=s1)and(s2 mod 6=0) then
      inc(s);
    end
  end;
 if s1>s2 then writeln(s1)
          else writeln(s2);
end.

var x,y,tek:longint;
begin
 read(x,y);
 tek:=1;
 while (x>0)or(y>0) do
  begin
   inc(tek);
   if tek mod 6 =0
    then begin
                if (y*3)>(x*2)
                 then begin dec(y);continue;end
                 else begin dec(x);continue;end;
         end;
   if tek mod 2 =0
    then  dec(x);
   if tek mod 3 =0
    then dec(y);

  end;
 write(tek);

end.

uses math;
const
        maxc=1000000000+69;
        modulo=1000000000+7;

type
        re=record
                x,y:longint;
        end;

var
        m,n:longint;
        a,b:array[0..1000000] of longint;

procedure mofile;
begin
        assign(input,'');
        reset(input);
        assign(output,'');
        rewrite(output);
end;

procedure dongfile;
begin
        close(input);
        close(output);
end;

procedure xuli;
var
        i:longint;
begin
        readln(n,m);
        for i:=1 to n do a[i]:=a[i-1]+2;
        for i:=1 to m do b[i]:=b[i-1]+3;

        i:=1;
        while i<=n do
        begin
                if (a[i] mod 3=0) and (b[m]>=a[i]) then
                begin
                        if a[n]+2<=b[m]+3 then
                        begin
                                inc(n);
                                a[n]:=a[n-1]+2;
                        end
                        else
                        begin
                                inc(m);
                                b[m]:=b[m-1]+3;
                        end;
                end;
                inc(i);
        end;
        writeln(max(a[n],b[m]));
end;

begin
        mofile;
        xuli;
        dongfile;
end.

uses math;
var
n,m,x,t1,t2,t3:int64;
i:longint;
begin
read(n,m);
for i:=1 to maxlongint do
begin
inc(x);
if(x mod 2=0) then inc(t1);
if(x mod 3=0) then inc(t2);
if(x mod 2=0) and (x mod 3=0) then begin inc(t3);  dec(t2); dec(t1); end;
if(t3>=   (max((n-t1),0))+(max((m-t2),0))) then break;
end;
writeln(i);
end.

        {$APPTYPE CONSOLE}
const nn=3; besk=2000000000000000000;
   nnn=2000000;  eps=1e-11; modul=1000000007;
 type matr=array[1..3,1..3] of extended;
   mat=^matr;
 label 1,2,3,4;

var i1,j1,k,step,kt,god,day,mon,mask,i0,j0,i,j,start,finish:longint;
newdl,dloch,kol,shag,m,t,ii,jj,l,r,p,p3,pos,ll,bb,pp,tt,ot1,ot2,s,kold,n:int64;
cc,q,t1,t2,p4,p1,p2,ot,dist1,vt,zap,ba,by,aa,ay,kk,centr,koef:int64;
flag2,flag1,flag:boolean;
ch1,ch2,ch:char;
str:array[-10..12000] of matr;
prob,ccc1,v,rr,h1,h2,h,r1,r2,aaa,bbb,ccc,hh,po,pt,doltek,dolpred:extended;
next,prev,x1,x2,y1,y2,d,och,newoch,f,x,y,fact,c,b,a,prost:array[-100000..1000000] of int64;
oldzan,oldmarked: array[0..330006] of boolean;
gr:array[-1..1001,-1..1001] of boolean;
agor,aver,ssumgor,ssumver,sgor,sver,udd,dostl,dostr: array[-100..600,-100..600] of int64;
det,ott :double;
dd:matr;
d3,d1,d2,dist,edin:matr;
ss,ss1,ss2:string;
za:array[-10..600,-10..600] of boolean;
zan,marked,dost,newdost:array[-10..20000000] of boolean;
ssnew:array[-10..1000000] of char;
pole:array[-10..610,-10..600] of char;
name:array[0..2000] of string;
function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

 function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

function degg(p,deg:int64):int64; var pp,q:int64;
 begin if deg=0 then degg:=1 else begin   if odd(deg) then degg:=(degg(p,deg-1)*p) mod modul else
 begin q:=(degg(p,deg shr 1)) mod modul; degg:=(q*q) mod modul;   end; end;   end;

function pok(t:int64):int64;
begin if t-bb>=0 then pok:=max((t-bb) div (bb-cc)+1,0) else pok:=0; end;

begin
 { assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
  }
    read(n,m);

   for i:=1 to 4000000 do zan[2*i]:=true;
   for i:=1 to 4000000 do zan[3*i]:=true;
   for i:=1 to 12000000 do
     begin
       if zan[i] then inc(p);
       if (p>=(n+m))and(i div 2>=n)and(i div 3>=m) then begin  write(i); goto 1; end;

     end;

   1:          close(output);
end.

Program Buntarik;
uses math;
var n,m,x1,x2:longint;

begin
{assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);  }

readln(n,m);
x1:=n*2; if m>0
then x2:=3+(m-1)*6
else
x2:=0;

if m>n
then writeln(m*3)
else
begin
while (x2>x1)and(x2>m*3)and(x2-x1>1) do
 begin
  dec(x2,6);
  inc(x1,2);
 end;
 writeln(max(x2,x1));
end;
{close(input);   close(output); }
end.

var
  n,m,i,x : longint;
  f : array[0..5000000] of longint;

begin
  readln(n,m);
  for x:=1 to 50000000 do if (n <= x div 2) and (m <= x div 3) and (n+m <= x div 2+x div 3-x div 6) then break;
  writeln(x);
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    a:= 2 * n;
    b:= 3 * m + 3 * (a div 6);

    if a > b then
        WriteLn (a)
    else
    begin
        while (b - a > 1) and (b > 3 * m) do
        begin
            Inc (a, 2);

            if (a mod 6 <> 0) and (b - a > 1) or (b - a < 3) then
                Dec (b, 3);
        end;

        if a > b then
            WriteLn (a)
        else if b > a then
            WriteLn (b)
        else
            WriteLn (a + 2);
    end
end.

uses math;

var i, n, m, cur, six, two, three: longint;

begin
  readln(n, m);
  for i := 1 to 10000000 do
  begin
    two := i div 2;
    three := i div 3;
    six := i div 6;
    two := two - six;
    three := three - six;
    cur := max(0, n - two) + max(0, m - three);
    if(cur <= six) then
    begin
      writeln(i);
      halt;
    end;
  end;
end.

uses math;
var
 n,m,k,l,w,s,j,i,k1,k2,k3:longint;
begin
 readln(n,m);
 for i:=1 to 12100000 do
 begin
  if (i mod 2=0)and(i mod 3=0) then inc(k3) else
  if i mod 2=0 then inc(k1) else
  if i mod 3=0 then inc(k2);
  if k3-max(0,n-k1)-max(0,m-k2)=0 then break;
 end;
 writeln(i);
end.

uses math;
var
     N,M,ans,L,R,sr,X,Y,ans1:Longint;
begin
     Readln(N,M);
     X:=2*N;
     Y:=3*M;
     ans:=0;
     while (N>0) and (M>0) do
begin
     Inc(ans);
     if ans mod 6=0 then begin
                              if X>Y then Dec(N)
                                     else Dec(M);
                          end
                    else
     if ans mod 2=0 then Dec(N)
                    else
     if ans mod 3=0 then Dec(M);
     X:=ans+2*N;
     Y:=ans+3*M;
 end;
     if M>0 then ans:=(ans div 3)*3+3*M;
     if N>0 then ans:=(ans div 2)*2+2*N;
     Writeln(ans);
 end.

uses math;
var pr,maxi1,maxi2,kol2,h11,h22,h1,h2,n,m,nn,mm,maxi,kol:int64;
begin
readln(n,m);

      nn:=n;
      mm:=m;

while(nn<>0)do
begin
if ((h1+2)mod 3=0)and(m*3>=(h1+2))then begin h1:=h1+4 ;inc(kol); end else h1:=h1+2;
dec(nn);
end;
h2:=m*3;
  pr:=0;

if h1>n*2 then
 while(pr<>1)do
 begin
 maxi1:=max(h1,h2);
 maxi2:=max(h1-2,h2+3);
 if ((h2+3)mod 2=0)and((h1-2)>=(h2+3))then begin h2:=h2+3;maxi2:=max(h2+3,h1-2);end;

 if (maxi1<maxi2)or(h1-2=h2+3)  then break else begin h1:=h1-2;h2:=h2+3;end;
 dec(kol);

 if kol=0 then break;
 end;

     pr:=0; maxi1:=0;maxi2:=0;

while(mm<>0)do
begin
if ((h22+3)mod 2=0)and(n*2>=(h22+3))then begin h22:=h22+6;inc(kol2);  end else h22:=h22+3;
dec(mm);
end;
h11:=n*2;

if h22>m*3 then
 while(pr<>1)do
 begin
 maxi1:=max(h11,h22);
 maxi2:=max(h11+2,h22-3);
 if ((h11+2)mod 3=0)and((h22-3)>=(h11+2))then begin h11:=h11+2;maxi2:=max(h11+2,h22-3);end;

 if (maxi1<maxi2)or(h11+2=h22-3) then break else begin h11:=h11+2;h22:=h22-3;end;
 dec(kol2);
 if kol2=0 then break;
 end;

writeln(min( max(h1,h2),max(h11,h22)  ));

end.

var
	n,m,a,b,x		: longint;
begin
	readln(n,m);

	if (2*n=3*m) then
	begin
		a:=(2*n div 6) mod 4;
		b:=(2*n div 6) div 4;
		case a of
			0	: writeln(2*n+b*6);
			1	: writeln(2*n+b*6+2);
			2	: writeln(2*n+b*6+3);
			3	: writeln(2*n+b*6+4);
		end;
	end;

	if (2*n>3*m) then
	begin

		x:=(2*n+4) div 6;
		if 4*x>(m+n)then
		begin
			if 2*n mod 6 = 2 then
			begin
				if 4*x-m-n>=3 then
				begin
					writeln(2*n);
				end else
					writeln(3*n+3+m-4*x);
			end else
				writeln(2*n);
		end else
		begin
			a:=(m+n-4*x) mod 4;
			b:=(m+n-4*x) div 4;
			case a of
				0	: writeln(6*x+b*6);
				1	: writeln(6*x+b*6+2);
				2	: writeln(6*x+b*6+3);
				3	: writeln(6*x+b*6+4);
			end;
		end;
	end;

	if (2*n<3*m) then
	begin
		x:=(3*m+3) div 6;
		if 4*x>(m+n)then
		begin
			if 3*m mod 6 = 3 then
			begin
				if 4*x-m-n>=2 then
				begin
					writeln(3*m);
				end else
					writeln(3*m+1);
			end else
				writeln(3*m);
		end else
		begin
			//writeln('yes',' ',m+n-4*x);
			a:=(m+n-4*x) mod 4;
			b:=(m+n-4*x) div 4;
			case a of
				0	: writeln(6*x+b*6);
				1	: writeln(6*x+b*6+2);
				2	: writeln(6*x+b*6+3);
				3	: writeln(6*x+b*6+4);
			end;
		end;
	end;
end.

uses math;
var n,m,t,h,ans:longint;
begin
    readln(n,m);
    ans:=0;
    while (n>m+1)and((n>2)or(m>0)) do begin dec(n,3);dec(m);inc(ans,6);end;
    while (n>0)and(m>0) do begin dec(n);dec(m);inc(ans,3);end;
    if m>0 then inc(ans,3*m);
    if n>0 then begin ans:=2*(ans div 2+1);n:=n-1;inc(ans,2*n);end;
    writeln(ans);
end.

var
n,m,i:longint;
begin
readln(n,m);
for i:=1 to 1000000000 do begin
    if ((i div 2 )>=n)and(i div 3>=m)and((i div 2)+(i div 3)-(i div 6)>=(n+m)) then
    break;
end;
writeln(i);
end.

{$mode objfpc}

var
 m,n,x:longint;

procedure input;
begin
 read(n,m);
end;

procedure process;
begin
 x:=1;
 while (n>x div 2) or (m>x div 3) or (m+n>(x div 2+x div 3-x div 6)) do inc(x);
end;

procedure output;
begin
 write(x);
end;

begin
 input;
 process;
 output;
end.

uses math;

var m,n,cn,cm,i:longint;

begin
  readln(n,m);
  cn:=2*n;
  cm:=3*m;
  i:=2;
  while i<=min(cn,cm) do
    begin
      inc(i,2);
      if i mod 3 = 0
        then
          if cn<=cm
            then cn:=cn+2
            else cm:=cm+3;
    end;
  writeln(max(cn,cm));
end.

uses math;

var minn,m,n,cn,cm,i:longint;

begin
  readln(n,m);
  cn:=2*n;
  cm:=3*m;
  i:=2;
  while i<=min(cn,cm) do
    begin
      inc(i,2);
      if i mod 3 = 0
        then
          if cn<=cm
            then cn:=cn+2
            else cm:=cm+3;
    end;
  writeln(max(cn,cm));
end.

{$MODE OBJFPC}
program dream_hyojoo;
uses math;
const maxN=1000000+1067;
var    n,m,i:integer;
       kt:array[0..3*maxN] of boolean;
       res1,res2,x,dem1,dem2,dem3:integer;

begin
       readln(n,m);
       x:=0;
       for i:=1 to 3000000 do
           begin
                if i mod 6=0 then inc(dem3) else
                if i mod 2=0 then inc(dem1) else
                if i mod 3=0 then inc(dem2);
                if (n-min(n,dem1)+m-min(m,dem2))<=dem3 then
                   begin
                       writeln(i);
                       halt
                   end;
           end;
end.

var
n,m,i:longint;
begin
     readln(n,m);
     for i:=1 to 4000000 do
     if (n<=i div 2) and (m<=i div 3) and ((n+m)<=(i div 2+i div 3-i div 6)) then begin write(i); halt; end;
end.

function fmn(a, b : int64) : int64;
begin
  if a < b
    then
      fmn := a
    else
      fmn := b;
end;
function fmx(a, b : int64) : int64;
begin
  if a > b
    then
      fmx := a
    else
      fmx := b;
end;

var
  n, h, m, k, i, max, min, z, d, c, ot, ot1, ot2 : int64;
begin
  read(n, m);
  min := fmn(n * 2, m * 3);
  k := 6;
  z := k;
  d := 1;
  while z <= min do
    begin
      inc(c);
      inc(d);
      z := k * d;
    end;
  while c > 0 do
    begin
      if n * 2 + 2 < m * 3 + 3
        then
          begin
            inc(n);
            if (n * 2 mod 3 = 0) and (n * 2 <= m * 3)
              then
                inc(c);
          end
        else
          begin
            inc(m);
            if (m * 3 mod 2 = 0) and (m * 3 <= n * 2)
              then
                inc(c);
          end;
      dec(c);
    end;
  //writeln(n * 2, ' ', m * 3);
  writeln(fmx(n * 2, m * 3));
end.

var
  n,m,ans,nn,mm,anss:longint;
begin
  readln(n,m); ans:=0;
  while (n>m+1)and((n>2)or(m>0)) do
    begin dec(n,3); dec(m); inc(ans,6); end; anss:=maxlongint >> 1;
  if (n=m+1)and(m and 1=1) then
    begin dec(n,2); dec(m); inc(ans,4); end;
  while (n>0)and(m>0) do
    begin dec(n); dec(m); inc(ans,3); end;
  if m>0 then inc(ans,3*m);
  if n>0 then inc(ans,2*n);
  writeln(ans);
end.

  Uses MATH;
  var N , M : LongInt;
       Two  ,Three , Six , Ans : Int64;
begin
  Two := 2;
  Three := 3;
  Six := 6;
  readLn ( N , M ) ;

  Ans := 0 ;

  while ( n + m > 0 ) do
  begin
    //writeLn ( N , ' ' , M ) ;
    if ( Six <= Two ) and ( Six <= Three ) then
    begin
      // Can both
      //writeLn ( 'Choose ' , n , ' ' , m ) ;
      Two := Two + 2 ;
      Three := Three + 3 ;
      if ( n >= m * 2  ) then
        dec ( n )
      else
        dec ( m ) ;
      Ans := Max ( Ans , Six ) ;
      Six := Six + 6 ;
    end
    else
    begin
      if ( Two < Three ) then
      begin
        if ( n > 0 ) then
        begin
          dec ( n ) ;
          Ans := Max ( ans , Two ) ;
        end;
        Two := Two + 2 ;
      end
      else
      begin
        if ( m > 0 ) then
        begin
          dec ( m ) ;
          Ans := Max ( ans , Three ) ;
        end;
        Three := Three + 3 ;
      end

    end;
  end;

  writeLn ( ans ) ;

end.

var
n,m,i,j,k:longint;
begin
readln(n,m);
i:=N*2;
j:=m*3;
k:=1;
while(k*6<=i) do begin
if j>=k*6
then begin
if i+2<j+3
then inc(i,2)
else inc(j,3);
end;
inc(k);
end;
if i>j
then writeln(i)
else writeln(j);
end.

uses math;
var kd,kt:int64;
    i:longint;

begin
readln(kd,kt);

for i:=2 to 5555555 do
 begin
  if (kd=0)and(kt=0) then break;

  if (i mod 2=0)  and (i mod 3<>0) then dec(kd);
  if (i mod 2<>0) and (i mod 3=0)  then dec(kt);

  if (i mod 6=0) then
                  if (kt*3)>(kd*2) then dec(kt)
                                   else dec(kd);
  kt:=max(0,kt);
  kd:=max(0,kd);
 end;

writeln(i-1);
end.

var n,m,i,x:longint;
begin
  readln(n,m);
  for i:=2 to 4000000 do
  begin
    if (n<=(i div 2)) and (m<=(i div 3)) and (n+m<=(i div 2)+(i div 3)-(i div 6))
                              then begin
                                     x:=i;
                                     break;
                                   end;
  end;
  writeln(x);
end.

function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end;
var
n,m,k,l,w,s,j,i,k1,k2,k3:longint;
begin
readln(n,m);
for i:=1 to 12345678 do
begin
if (i mod 2=0) and (i mod 3=0) then inc(k3) else
if i mod 2=0 then inc(k1) else
if i mod 3=0 then inc(k2);
if k3-max(0,n-k1)-max(0,m-k2)=0 then break;
end;
writeln(i);
end.

uses math;
var n,m,mn,lik,t,kk,jj,minn:int64;
i,j:longint;
a:array [0..3000000] of int64;
ans,NN,MM:int64;

begin
readln(n,m);
nn:=n*2; T:=0;
mm:=m*3;
for i:=1 to 3000000 do
if (i mod 2=0)and(i mod 3=0) then begin inc(t);a[t]:=i;end;

minn:=maxlongint;
for i:=1 to t do
begin

if (a[i]<=nn)and(a[i]<=mm)and(nn>mm) then
                         begin minn:=abs(nn-mm);mm:=mm+3;end  else

if (a[i]<=nn)and(a[i]<=mm)and(nn<=mm)then
                         begin minn:=abs(nn-mm);nn:=nn+2;end;

end;
writelN(max(mm,nn));

end.

var x,y,tek:longint;
begin
 read(x,y);
 tek:=1;
 while (x>0)or(y>0) do
  begin
   inc(tek);
   if tek mod 6 =0
    then begin
                if y>0
                 then begin dec(y);continue;end
                 else begin dec(x);continue;end;
         end;
   if tek mod 2 =0
    then  dec(x);
   if tek mod 3 =0
    then dec(y);

  end;
 write(tek);

end.

uses math;
var
a,b,t,m2,m1:int64;
begin
read(a,b);
m1:=a*2;
m2:=b*3;
a:=max(m1,m2);
t:=min(m1 div 3,m2 div 2);
if(t=0) then begin writeln(a); halt; end;
inc(a);
while(t>0) do
begin
if(a mod 3=0) or (a mod 2=0) then dec(t);
inc(a);
end;
writeln(a);
end.

uses math;
var
a,b,t,m2,m1:int64;
begin
read(a,b);
m1:=a*2;
m2:=b*3;
a:=max(m1,m2);
t:=min(m1 div 3,m2 div 2);
if(t=0) then begin writeln(a); halt; end;
inc(a);
while(t>0) do
begin
if(a mod 3=0) or (a mod 2=0) then dec(t);
inc(a);
end;
end.

uses math;
var
n,m,m1,m2,t,z,z1,z2,t1:int64;
i:longint;
begin
readln(n,m);
m1:=n*2;
m2:=m*3;
t:=n div 3;
t1:=m div 2;
z:=min(t,t1);
z2:=2;
for i:=1 to z do
begin
if(z2=2) then begin m1:=m1+2; z2:=3; end else begin m2:=m2+3; z2:=2;  end;
end;
writeln(max(m1,m2));
end.

uses math;
var
a,b,t,m2,m1:int64;
begin
read(a,b);
m1:=a*2;
m2:=b*3;
t:=min(a div 3,b div 2);
a:=max(m1,m2);
if(t=0) then begin writeln(a); halt; end;
inc(a);
while(t>0) do
begin
if(a mod 3=0) or (a mod 2=0) then dec(t);
inc(a);
end;
writeln(a);
end.

uses math;
var
n,m,m1,m2,t,z,z1,z2,t1:int64;
i:longint;
begin
readln(n,m);
t:=1;
while(n>0) or (m>0) do
begin
if(t mod 2=1) then
begin
if((m1+2) mod 3=0) and ((m1+2)<=m2) then m1:=m1+4
else
m1:=m1+2;
dec(n);
end;
if(t mod 2=0) then
begin
if((m2+3) mod 2=0) and ((m2+3)<=m1) then m2:=m2+6
else
m2:=m2+3;
dec(m);
end;
inc(t);
end;
writeln(max(m1,m2));
end.

uses math;
var
a,b,t,m2,m1:int64;
begin
read(a,b);
m1:=a*2;
m2:=b*3;
a:=max(m1,m2);
t:=min(a div 3,b div 2);
if(t=0) then begin writeln(a); halt; end;
inc(a);
while(t>0) do
begin
if(a mod 3=0) or (a mod 2=0) then dec(t);
inc(a);
end;
writeln(a);
end.

var
n,m,x,t1,t2,t3:int64;
i:longint;
begin
read(n,m);
for i:=1 to maxlongint do
begin
inc(x);
if(x mod 2=0) then inc(t1);
if(x mod 3=0) then inc(t2);
if(x mod 2=0) and (x mod 3=0) then inc(t3);
if(n+m<=(t1+t2-t3)) then break;
end;
writeln(i);
end.

uses math;
var
a,b,t,m2,m1:int64;
begin
read(a,b);
m1:=a*2;
m2:=b*3;
t:=min(a div 3,b div 2);
a:=max(m1,m2);
if(t=0) then begin writeln(a); halt; end;
inc(a);
while(t>0) do
begin
if(a mod 3=0) or (a mod 2=0) then dec(t);
if(t<>0) then inc(a);
end;
writeln(a);
end.

Program Buntarik;
uses math;
var n,m,x1,x2:longint;

begin
{assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);  }

readln(n,m);
x1:=n*2; if m>0
then x2:=3+(m-1)*6
else
x2:=0;

while (x2>x1)and(x2>m*3) do
 begin
  dec(x2,3);
  inc(x1,2);
 end;
 writeln(max(x2,x1));
{close(input);   close(output);  }
end.

Program Buntarik;
uses math;
var n,m,x1,x2:longint;

begin
{assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);  }

readln(n,m);
x1:=n*2; if m>0
then x2:=3+(m-1)*6
else
x2:=0;

while (x2>x1)and(x2>m*3)and(x2-x1>1) do
 begin
  dec(x2,3);
  inc(x1,2);
 end;
 writeln(max(x2,x1));
{close(input);   close(output);  }
end.

Program Buntarik;
uses math;
var n,m,x1,x2:longint;

begin
{assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);  }

readln(n,m);
x1:=n*2; if m>0
then x2:=3+(m-1)*6
else
x2:=0;

while (x2>x1)and(x2>m*3)and(x2-x1>1) do
 begin
  dec(x2,6);
  inc(x1,2);
 end;
 writeln(max(x2,x1));
{close(input);   close(output); }
end.

var
  n,m,i,mx : longint;
  f : array[0..5000000] of longint;

begin
  readln(n,m);
  for i:=1 to m do f[i*3]:=1;
  mx:=m*3; i:=2;
  while n > 0 do begin
    while f[i] = 1 do i:=i+2;
    f[i]:=1;
    if i > mx then mx:=i;
    dec(n);
  end;
  writeln(mx);
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    a:= 2 * n;
    b:= 3 * m + 3 * (a div 6);

    if a > b then
        WriteLn (a)
    else
    begin
        while (Abs (a - b) > 1) and (b > 3 * m) do
        begin
            Inc (a, 2);
            Dec (b, 3);

            if a mod 6 = 0 then
                Inc (a, 2);
        end;

        if a > b then
            WriteLn (a)
        else
            WriteLn (b)
    end
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    a:= 2 * n;
    b:= 3 * m + 3 * (a div 6);

    if a > b then
        WriteLn (a)
    else
    begin
        while (Abs (a - b) > 1) and (b > 3 * m) do
        begin
            Inc (a, 2);

            if a mod 6 <> 0 then
                Dec (b, 3);
        end;

        if a > b then
            WriteLn (a)
        else
            WriteLn (b)
    end
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    a:= 2 * n;
    b:= 3 * m + 3 * (a div 6);

    if a > b then
        WriteLn (a)
    else
    begin
        while (Abs (a - b) > 1) and (b > 3 * m) do
        begin
            Inc (a, 2);
            Dec (b, 3);

            if a mod 6 = 0 then
                Inc (a, 2);
        end;

        if a > b then
            WriteLn (a)
        else
            WriteLn (b);

        WriteLn (a, ' ', b)
    end
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    a:= 2 * n;
    b:= 3 * m + 3 * (a div 6);

    if a > b then
        WriteLn (a)
    else
    begin
        while (b - a > 1) and (b > 3 * m) do
        begin
            Inc (a, 2);

            if (a mod 6 <> 0) and (b - a > 1) or (b - a < 3) then
                Dec (b, 3);
        end;

        WriteLn (a, ' ', b);

        if a > b then
            WriteLn (a)
        else if b > a then
            WriteLn (b)
        else
            WriteLn (a + 2);
    end
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    a:= 2 * n;
    b:= 3 * m + 3 * (a div 6);

    if a > b then
        WriteLn (a)
    else
    begin
        while (b - a > 1) and (b > 3 * m) do
        begin
            Inc (a, 2);

            if a mod 6 <> 0 then
                Dec (b, 3);
        end;

        if a > b then
            WriteLn (a)
        else if b > a then
            WriteLn (b)
        else
            WriteLn (a + 2);
    end
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    a:= 2 * n;
    b:= 3 * m + 3 * (a div 6);

    if a > b then
        WriteLn (a)
    else
    begin
        while (Abs (a - b) > 1) and (b > 3 * m) do
        begin
            Inc (a, 2);
            Dec (b, 3)
        end;

        if a > b then
            WriteLn (a)
        else
            WriteLn (b)
    end
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    b:= 3 * m;

    a:= 0;
    for i:= 1 to n do
    begin
        Inc (a, 2);

        if (a mod 6 = 0) and (a <= b) then
            Inc (a, 2)
    end;

    if b > a then
        WriteLn (b)
    else if a > b + 3 then
        WriteLn (b + 3)
    else
        WriteLn (a);
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    b:= 3 * m;

    a:= 2;
    for i:= 2 to n do
    begin
        Inc (a, 2);

        if (a mod 6 = 0) and (a <= b) then
            Inc (a, 2)
    end;

    if a > b then
        WriteLn (a)
    else
        WriteLn (b);
end.

var
    n, m, i: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    b:= 3 * m;

    a:= 0;
    for i:= 1 to n do
    begin
        Inc (a, 2);

        if (a mod 6 = 0) and (a <= b) then
            Inc (a, 2)
    end;

    if a > b then
        WriteLn (a)
    else
        WriteLn (b);
end.

var
    n, m: LongInt;
    a, b: Int64;

begin
    Read (n, m);

    a:= 2 * n;
    b:= 3 * m;

    if a > b then
        WriteLn (a)
    else if b > a then
        WriteLn (b)
    else
        WriteLn (a + 2)
end.

var
 n,m,k,l,w,s,j,i:longint;
begin
 readln(n,m);
 for i:=1 to 12100000 do
 begin
  if (i mod 3=0)and(m>0) then begin w:=i; dec(m); end else
  if (i mod 2=0)and(n>0) then begin w:=i; dec(n); end;
  if (n=0)and(m=0) then break;
 end;
 writeln(w);
end.

var
 n,m,k,l,w,s,j,i:longint;
begin
 readln(n,m);
 for i:=1 to 12100000 do
 begin
  if (i mod 3=0)and(m>0)and(m>=n) then begin w:=i; dec(m); end else
  if (i mod 2=0)and(n>0) then begin w:=i; dec(n); end;
  if (n=0)and(m=0) then break;
 end;
 writeln(w);
end.

uses math;
var
     N,M,ans,L,R,sr,X,Y,ans1:Longint;
begin
     Readln(N,M);
     ans:=M*3;
     Y:=ans div 6;
     L:=0;
     R:=3000300;
     while R-L>1 do
begin
     sr:=(L+R) div 2;
     if sr div 2-min(Y,sr div 6)>=N then R:=sr
                             else L:=sr;
 end;
     if L div 2-min(Y,L div 6)=N then X:=L
                          else X:=R;
     //X:=2*(X div 2+1);
     ans:=max(ans,x);
     ans1:=N*2;
     Y:=ans1 div 6;
     L:=0;
     R:=3000300;
     while R-L>1 do
begin
     sr:=(L+R) div 2;
     if sr div 3-min(Y,sr div 6)>=m then R:=sr
                                    else L:=sr;
 end;
     if L div 3-min(Y,L div 6)=M then X:=L
                                 else X:=R;
     //X:=2*(X div 2+1);
     ans1:=max(ans1,x);
     ans:=min(ans,ans1);
     Writeln(ans);
 end.

uses math;
var
     N,M,ans,L,R,sr,X,Y:Longint;
begin
     Readln(N,M);
     ans:=M*3;
     Y:=ans div 6;
     L:=0;
     R:=3000300;
     while R-L>1 do
begin
     sr:=(L+R) div 2;
     if sr div 2-min(Y,sr div 6)>=N then R:=sr
                             else L:=sr;
 end;
     if L div 2-min(Y,L div 6)=N then X:=L
                          else X:=R;
     //X:=2*(X div 2+1);
     ans:=max(ans,x);
     Writeln(ans);
 end.

uses math;
var pr,maxi1,maxi2,kol2,h11,h22,h1,h2,n,m,nn,mm,maxi,kol:int64;
begin
readln(n,m);

      nn:=n;
      mm:=m;

while(nn<>0)do
begin
if ((h1+2)mod 3=0)and(m*3>=(h1+2))then begin h1:=h1+4 ;inc(kol); end else h1:=h1+2;
dec(nn);
end;
h2:=m*3;
  pr:=0;
if h1>n*2 then
 while(pr<>1)do
 begin
 maxi1:=max(h1,h2);
 maxi2:=max(h1-2,h2+3);

 if (maxi1<maxi2)or(h1-2=h2+3)  then break else begin h1:=h1-2;h2:=h2+3;end;
 dec(kol);
 if kol=0 then break;
 end;
     pr:=0; maxi1:=0;maxi2:=0;

while(mm<>0)do
begin
if ((h22+3)mod 2=0)and(n*2>=(h22+3))then begin h22:=h22+6;inc(kol2);  end else h22:=h22+3;
dec(mm);
end;
h11:=n*2;

if h22>m*3 then
 while(pr<>1)do
 begin
 maxi1:=max(h11,h22);
 maxi2:=max(h11+2,h22-3);
 if (maxi1<maxi2)or(h11+2=h22-3) then break else begin h11:=h11+2;h22:=h22-3;end;
 dec(kol2);
 if kol2=0 then break;
 end;

writeln(min( max(h1,h2),max(h11,h22)  ));

end.

uses math;
var pr,maxi1,maxi2,kol2,h11,h22,h1,h2,n,m,nn,mm,maxi,kol:int64;
begin
readln(n,m);

      nn:=n;
      mm:=m;

while(nn<>0)do
begin
if ((h1+2)mod 3=0)and(m*3>=(h1+2))then begin h1:=h1+4 ;inc(kol); end else h1:=h1+2;
dec(nn);
end;
h2:=m*3;
  pr:=0;
if h1>n*2 then
 while(pr<>1)do
 begin
 maxi1:=max(h1,h2);
 maxi2:=max(h1-2,h2+3);
 if maxi1<maxi2 then break else begin h1:=h1-2;h2:=h2+3;end;
 end;
     pr:=0; maxi1:=0;maxi2:=0;

while(mm<>0)do
begin
if ((h22+3)mod 2=0)and(n*2>=(h22+3))then begin h22:=h22+6;inc(kol2);  end else h22:=h22+3;
dec(mm);
end;
h11:=n*2;

if h22>m*3 then
 while(pr<>1)do
 begin
 maxi1:=max(h11,h22);
 maxi2:=max(h11+2,h22-3);
 if maxi1<maxi2 then break else begin h11:=h11+2;h22:=h22-3;end;
 end;

writeln(min( max(h1,h2),max(h11,h22)  ));

end.

uses math;
var pr,maxi1,maxi2,kol2,h11,h22,h1,h2,n,m,nn,mm,maxi,kol:int64;
begin
readln(n,m);

      nn:=n;
      mm:=m;

while(nn<>0)do
begin
if ((h1+2)mod 3=0)and(m*3>=(h1+2))then begin h1:=h1+4 ;inc(kol); end else h1:=h1+2;
dec(nn);
end;
h2:=m*3;
  pr:=0;
if h1>n*2 then
 while(pr<>1)do
 begin
 maxi1:=max(h1,h2);
 maxi2:=max(h1-2,h2+3);

 if maxi1<maxi2 then break else begin h1:=h1-2;h2:=h2+3;end;
 dec(kol);
 if kol=0 then break;
 end;
     pr:=0; maxi1:=0;maxi2:=0;

while(mm<>0)do
begin
if ((h22+3)mod 2=0)and(n*2>=(h22+3))then begin h22:=h22+6;inc(kol2);  end else h22:=h22+3;
dec(mm);
end;
h11:=n*2;

if h22>m*3 then
 while(pr<>1)do
 begin
 maxi1:=max(h11,h22);
 maxi2:=max(h11+2,h22-3);
 if maxi1<maxi2 then break else begin h11:=h11+2;h22:=h22-3;end;
 dec(kol2);
 if kol2=0 then break;
 end;

writeln(min( max(h1,h2),max(h11,h22)  ));

end.

var
	n,m,a,b,x		: longint;
begin
	readln(n,m);

	if (2*n=3*m) then
	begin
		a:=(2*n div 6) mod 4;
		b:=(2*n div 6) div 4;
		case a of
			0	: writeln(2*n+b*6);
			1	: writeln(2*n+b*6+2);
			2	: writeln(2*n+b*6+3);
			3	: writeln(2*n+b*6+4);
		end;
	end;

	if (2*n>3*m) then
	begin
		x:=(2*n+4) div 6;
		if 4*x>(m+n)then
		begin
			if 2*n mod 6 = 2 then
			begin
				if 4*x-m-n>3 then
				begin
					writeln(2*n);
				end else
					writeln(2*n+1);
			end else
				writeln(2*n);
		end else
		begin
			a:=(m+n-4*x) mod 4;
			b:=(m+n-4*x) div 4;
			case a of
				0	: writeln(6*x+b*6);
				1	: writeln(6*x+b*6+2);
				2	: writeln(6*x+b*6+3);
				3	: writeln(6*x+b*6+4);
			end;
		end;
	end;

	if (2*n<3*m) then
	begin
		x:=(3*m+3) div 6;
		if 4*x>(m+n)then
		begin
			if 3*m mod 6 = 3 then
			begin
				if 4*x-m-n>2 then
				begin
					writeln(3*m);
				end else
					writeln(3*m+1);
			end else
				writeln(3*m);
		end else
		begin
			//writeln('yes',' ',m+n-4*x);
			a:=(m+n-4*x) mod 4;
			b:=(m+n-4*x) div 4;
			case a of
				0	: writeln(6*x+b*6);
				1	: writeln(6*x+b*6+2);
				2	: writeln(6*x+b*6+3);
				3	: writeln(6*x+b*6+4);
			end;
		end;
	end;
end.

var
	n,m,a,b,x		: longint;
begin
	readln(n,m);

	if (2*n=3*m) then
	begin
		a:=(2*n div 6) mod 4;
		b:=(2*n div 6) div 4;
		case a of
			0	: writeln(2*n+b*6);
			1	: writeln(2*n+b*6+2);
			2	: writeln(2*n+b*6+3);
			3	: writeln(2*n+b*6+4);
		end;
	end;

	if (2*n>3*m) then
	begin

		x:=(2*n+4) div 6;
		if 4*x>(m+n)then
		begin
			if 2*n mod 6 = 2 then
			begin
				if 4*x-m-n>=3 then
				begin
					writeln(2*n);
				end else
					writeln(2*n+1);
			end else
				writeln(2*n);
		end else
		begin
			a:=(m+n-4*x) mod 4;
			b:=(m+n-4*x) div 4;
			case a of
				0	: writeln(6*x+b*6);
				1	: writeln(6*x+b*6+2);
				2	: writeln(6*x+b*6+3);
				3	: writeln(6*x+b*6+4);
			end;
		end;
	end;

	if (2*n<3*m) then
	begin
		x:=(3*m+3) div 6;
		if 4*x>(m+n)then
		begin
			if 3*m mod 6 = 3 then
			begin
				if 4*x-m-n>=2 then
				begin
					writeln(3*m);
				end else
					writeln(3*m+1);
			end else
				writeln(3*m);
		end else
		begin
			//writeln('yes',' ',m+n-4*x);
			a:=(m+n-4*x) mod 4;
			b:=(m+n-4*x) div 4;
			case a of
				0	: writeln(6*x+b*6);
				1	: writeln(6*x+b*6+2);
				2	: writeln(6*x+b*6+3);
				3	: writeln(6*x+b*6+4);
			end;
		end;
	end;
end.

var
	n,m,a,b,x		: longint;
begin
	readln(n,m);

	if (2*n=3*m) then
	begin
		a:=(2*n div 6) mod 4;
		b:=(2*n div 6) div 4;
		case a of
			0	: writeln(2*n+b*6);
			1	: writeln(2*n+b*6+2);
			2	: writeln(2*n+b*6+3);
			3	: writeln(2*n+b*6+4);
		end;
	end;

	if (2*n>3*m) then
	begin
		x:=2*n+4 div 6;
		if 4*x>(m+n)then
		begin
			if 2*n mod 6 =4 then
			begin
				if 4*x-m-n>3 then
				begin
					writeln(2*n);
				end else
					writeln(2*n+1);
			end else
				writeln(2*n);
		end else
		begin
			a:=x mod 4;
			b:=x;
			case a of
				0	: writeln(4*x+b*6);
				1	: writeln(4*x+b*6+2);
				2	: writeln(4*x+b*6+3);
				3	: writeln(4*x+b*6+4);
			end;
		end;
	end;

	if (2*n<3*m) then
	begin
		x:=3*m+3 div 6;
		if 4*x>(m+n)then
		begin
			if 2*m mod 6 = 3 then
			begin
				if 4*x-m-n>2 then
				begin
					writeln(3*m);
				end else
					writeln(3*m+1);
			end else
				writeln(3*m);
		end else
		begin
			a:=x mod 4;
			b:=x;
			case a of
				0	: writeln(4*x+b*6);
				1	: writeln(4*x+b*6+2);
				2	: writeln(4*x+b*6+3);
				3	: writeln(4*x+b*6+4);
			end;
		end;
	end;
end.

var
	n,m,a,b,x		: longint;
begin
	readln(n,m);

	if (2*n=3*m) then
	begin
		a:=(2*n div 6) mod 4;
		b:=(2*n div 6) div 4;
		case a of
			0	: writeln(2*n+b*6);
			1	: writeln(2*n+b*6+2);
			2	: writeln(2*n+b*6+3);
			3	: writeln(2*n+b*6+4);
		end;
	end;

	if (2*n>3*m) then
	begin
		x:=(2*n+4) div 6;
		if 4*x>(m+n)then
		begin
			if 2*n mod 6 = 2 then
			begin
				if 4*x-m-n>3 then
				begin
					writeln(2*n);
				end else
					writeln(2*n+1);
			end else
				writeln(2*n);
		end else
		begin
			a:=(m+n-4*x) mod 4;
			b:=(m+n-4*x) div 4;
			case a of
				0	: writeln(6*x+b*6);
				1	: writeln(6*x+b*6+2);
				2	: writeln(6*x+b*6+3);
				3	: writeln(6*x+b*6+4);
			end;
		end;
	end;

	if (2*n<3*m) then
	begin
		x:=(3*m+3) div 6;
		if 4*x>(m+n)then
		begin
			if 2*m mod 6 = 3 then
			begin
				if 4*x-m-n>2 then
				begin
					writeln(3*m);
				end else
					writeln(3*m+1);
			end else
				writeln(3*m);
		end else
		begin
			//writeln('yes',' ',m+n-4*x);
			a:=(m+n-4*x) mod 4;
			b:=(m+n-4*x) div 4;
			case a of
				0	: writeln(6*x+b*6);
				1	: writeln(6*x+b*6+2);
				2	: writeln(6*x+b*6+3);
				3	: writeln(6*x+b*6+4);
			end;
		end;
	end;
end.

var
	n,m,a,b,x		: longint;
begin
	readln(n,m);

	if (2*n=3*m) then
	begin
		a:=(2*n div 6) mod 4;
		b:=(2*n div 6) div 4;
		case a of
			0	: writeln(2*n+b*6);
			1	: writeln(2*n+b*6+2);
			2	: writeln(2*n+b*6+3);
			3	: writeln(2*n+b*6+4);
		end;
	end;

	if (2*n>3*m) then
	begin
		x:=(2*n+4) div 6;
		if 4*x>(m+n)then
		begin
			if 2*n mod 6 = 2 then
			begin
				if 4*x-m-n>3 then
				begin
					writeln(2*n);
				end else
					writeln(2*n+1);
			end else
				writeln(2*n);
		end else
		begin
			a:=x mod 4;
			b:=x;
			case a of
				0	: writeln(4*x+b*6);
				1	: writeln(4*x+b*6+2);
				2	: writeln(4*x+b*6+3);
				3	: writeln(4*x+b*6+4);
			end;
		end;
	end;

	if (2*n<3*m) then
	begin
		x:=(3*m+3) div 6;
		if 4*x>(m+n)then
		begin
			if 2*m mod 6 = 3 then
			begin
				if 4*x-m-n>2 then
				begin
					writeln(3*m);
				end else
					writeln(3*m+1);
			end else
				writeln(3*m);
		end else
		begin
			a:=x mod 4;
			b:=x;
			case a of
				0	: writeln(4*x+b*6);
				1	: writeln(4*x+b*6+2);
				2	: writeln(4*x+b*6+3);
				3	: writeln(4*x+b*6+4);
			end;
		end;
	end;
end.

uses math;
var n,m:longint;
begin
    readln(n,m);
    n:=n+min(n div 3,m);
    writeln(max(n*2,m*3));
end.

var n,m,ans,d:int64;
    begin
    readln(n,m);
    ans:=m*3;
    if n>m then
      begin
      d:=n-m;
      if ans mod 2=1 then
        begin
        ans:=ans+1;
        d:=d-1;
        end;
      ans:=ans+d*2;
      end;
    write(ans);
    end.

var n,m,c:longint;
    cn,cm:longint;

begin
  readln(n,m);
  if n=0
    then writeln(m*3)
    else if m=0
    then writeln(n*2)
    else
      begin
        cn:=n div 3;
        cm:=m div 2;
        if cn>cm
          then
            cn:=cm;
        c:=n*2+(cn*2);
        if c<m*3 then c:=m*3;
        cm:=m*3;
        while c>cm+3 do
          begin
            c:=c-2;
            cm:=cm+3;
          end;
        writeln(c);
      end;
end.

var n,m,c:longint;
    cn,cm:longint;

begin
  readln(n,m);
  if n=0
    then writeln(m*3)
    else if m=0
    then writeln(n*2)
    else
      begin
        cn:=n div 3;
        cm:=m div 2;
        if cn>cm
          then
            cn:=cm;
        c:=n*2+(cn*2);
        if c<m*3 then c:=m*3;
        cm:=m*3;
        while c>cm+3 do
          begin
            c:=c-2;
            cm:=cm+3;
          end;
        if cm>c then c:=cm;
        writeln(c);
      end;
end.

var n,m,c:longint;
    cn,cm:longint;

begin
  readln(n,m);
  if n=0
    then writeln(m*3)
    else if m=0
    then writeln(n*2)
    else
      begin
        cn:=n div 3;
        cm:=m div 2;
        if cn>cm
          then
            cn:=cm;
        c:=n*2+(cn*2);
        cm:=m*3;
        while c>cm+3 do
          begin
            c:=c-2;
            cm:=cm+3;
          end;
        writeln(c);
      end;
end.

var n,m,c:longint;
    cn,cm:longint;

begin
  readln(n,m);
  if n=0
    then writeln(m*3)
    else if m=0
    then writeln(n*2)
    else
      begin
        cn:=n div 3;
        cm:=m div 2;
        if cn>cm
          then
            cn:=cm;
        c:=m*3+(cn*2);
        cm:=m*3;
        while c>cm+3 do
          begin
            c:=c-2;
            cm:=cm+3;
          end;
        writeln(c);
      end;
end.

var n,m,c:longint;
    cn,cm:longint;

begin
  readln(n,m);
  if n=0
    then writeln(m*3)
    else if m=0
    then writeln(n*2)
    else
      begin
        cn:=n div 3;
        cm:=m div 2;
        if cn>cm
          then
            cn:=cm;
        c:=n*2+(cn*2);
        if c<m*3 then c:=m*3;
        cm:=m*3;
        while (c>cm+3)and(cn>0) do
          begin
            c:=c-2;
            cm:=cm+3;
            dec(cn);
          end;
        if cm>c then c:=cm;
        writeln(c);
      end;
end.

var
n,m,i:longint;
a,b:array[0..10000000] of longint;
begin
     readln(n,m);
     a[0]:=0;
     for i:=1 to 2000000 do
     begin a[i]:=a[i-1]+2; if (i mod 3 = 0) and (i*2 div 3<=m) then a[i]:=a[i]+2; end;
     b[0]:=0;
     for i:=1 to 2000000 do b[i]:=i*3;

     if a[n]>b[m] then write(a[n]) else write(b[m]);
end.

var
n,m,i:longint;
begin
     readln(n,m);
     for i:=1 to 4000000 do
     if (n<=i div 2) and (m<=i div 2) and (n+m<=i div 2+i div 3-i div 6) then begin write(i); halt; end;
end.

var
n,m,i:longint;
begin
     readln(n,m);
     for i:=1 to 4000000 do
     if (n<=trunc(i/2)) and (m<=trunc(i/2)) and (n+m<=trunc(i/2)+trunc(i/3)-trunc(i/6)) then begin write(i); halt; end;
end.

function fmn(a, b : int64) : int64;
begin
  if a < b
    then
      fmn := a
    else
      fmn := b;
end;
function fmx(a, b : int64) : int64;
begin
  if a > b
    then
      fmx := a
    else
      fmx := b;
end;

var
  n, h, m, k, i, max, min, z, d, c, ot, ot1, ot2 : int64;
begin
  read(n, m);
  min := fmn(n * 2, m * 3);
  k := 6;
  z := k;
  d := 1;
  while z < 1000 do
    begin
      if z <= min
        then
          inc(c);
      inc(d);
      z := k * d;
    end;
  h := c div 2;
  if c mod 2 = 1
    then
      inc(h);
  inc(n, h);
  inc(m, c - h);
  if n * 2 = m * 3
    then
      ot := n * 2 + 2
    else
  ot := fmx(n * 2, m * 3);
  {for i := 1 to 100 do
    if a[i] = 1
      then
        write(i, ' ');
  writeln;}
  writeln(ot);
end.

var
  n,m,i,max,now:longint;
  f:array[0..4000001]of longint;
begin
  readln(n,m);
  for i:=1 to m do f[3*i]:=1;
  max:=3*m; now:=0;
  for i:=1 to n+m do
    begin
      if f[i << 1]=0 then inc(now);
      if now=n then begin
        if max<i << 1 then max:=i << 1;
        break; end;
    end;
  writeln(max);
end.

var
  n,m,ans:longint;
begin
  readln(n,m); ans:=0;
  while (n>m+1)and((n>2)or(m>0)) do
    begin dec(n,3); dec(m); inc(ans,6); end;
  if n=m+1 then
    begin dec(n,2); dec(m); inc(ans,4); end;
  while (n>0)and(m>0) do
    begin dec(n); dec(m); inc(ans,3); end;
  if m>0 then inc(ans,3*m);
  if n>0 then inc(ans,2*n);
  writeln(ans);
end.

var
n,m,i,j,k:longint;
begin
readln(n,m);
i:=N*2;
j:=m*3;
for k:=1 to i div 6 do
if j>=k*6
then begin
if i+2<j+3
then inc(i,2)
else inc(j,3);
end;
if i>j
then writeln(i)
else writeln(j);
end.

var a,b,da,db,d1,d2,i,kl1,kl2,min:longint;
begin
  readln(a,b);
  a:=a*2;
  b:=b*3;
  d1:=a;
  d2:=b;
  da:=(a div 3) div 2;
  db:=(b div 3) div 2;
  if da<db then min:=da
           else min:=db;
  for i:=1 to min do
  begin
    if a<b then a:=a+2
    else if b<a then b:=b+3
    else if a=b then a:=a+2
  end;
  if d1=a then begin
                 a:=2;
                 kl1:=1;
               end
  else if d2=b then begin
                 b:=3;
                 kl2:=1;
               end;
  if (a mod 3=0) and (b mod 2=0) and (a=b) then a:=a+2
  else if (a mod 3=0) and (b mod 2=0) and (a<>b) then begin
                                                        a:=a+2;
                                                        b:=b+3;
                                                      end
  else if (a mod 3=0) and (b mod 2<>0) then a:=a+2
  else if (a mod 3<>0) and (b mod 2=0) then b:=b+3;
  if kl1=1 then a:=d1;
  if kl2=1 then b:=d2;
  if a>b then min:=a
         else min:=b;
  writeln(min);
end.

var c:array[1..3000000]of longint;
a,b,da,db,d1,d2,i,max,kl1,kl2,min:longint;
begin
  readln(a,b);
  a:=a*2;
  b:=b*3;
  d1:=a;
  d2:=b;
  da:=(a div 3) div 2;
  db:=(b div 3) div 2;
  if a<b then begin
               min:=da;
               max:=db;
              end
           else begin
                  min:=db;
                  max:=da;
                end;
  for i:=1 to min*3*2 do
  begin
    if (i mod 3=0) and (i mod 2=0) then c[i]:=1;
  end;
  i:=0;
  while true do
  begin
    i:=i+1;
    if i>min then break;
    if a<b then begin
                  a:=a+2;
                  if (a<=b) and (a mod 3=0) and (c[a]=0)
                                       then begin
                                              min:=min+1;
                                              c[a]:=1;
                                            end;
                end
    else if b<a then begin
                       b:=b+3;
                       if (a>=b) and (b mod 2=0) and (c[b]=0)
                                         then begin
                                           min:=min+1;
                                           c[b]:=1;
                                          end;
                     end
    else if a=b then begin
                       a:=a+2;
                       if (a<=b) and (a mod 3=0) and (c[a]=0)
                                        then begin
                                               min:=min+1;
                                               c[a]:=1;
                                             end;
                     end
  end;
  if d1=a then begin
                 a:=2;
                 kl1:=1;
               end
  else if d2=b then begin
                 b:=3;
                 kl2:=1;
               end;
  if (a mod 3=0) and (b mod 2=0) and (a=b) then a:=a+2
  else if (a mod 3=0) and (b mod 2=0) and (a<>b) then begin
                                                        a:=a+2;
                                                        b:=b+3;
                                                      end
  else if (a mod 3=0) and (b>=a) then a:=a+2
  else if (a>=b) and (b mod 2=0) then b:=b+3;
  if kl1=1 then a:=d1;
  if kl2=1 then b:=d2;
  if a>b then min:=a
         else min:=b;
  writeln(min);
end.

var a,b,da,db,d1,d2,i,kl1,kl2,min:longint;
begin
  readln(a,b);
  a:=a*2;
  b:=b*3;
  d1:=a;
  d2:=b;
  da:=(a div 3) div 2;
  db:=(b div 3) div 2;
  if da>db then min:=da
           else min:=db;
  for i:=1 to min do
  begin
    if a<b then a:=a+2
    else if b<a then b:=b+3
    else if a=b then a:=a+2
  end;
  if d1=a then begin
                 a:=2;
                 kl1:=1;
               end
  else if d2=b then begin
                 b:=3;
                 kl2:=1;
               end;
  if (a mod 3=0) and (b mod 2=0) and (a=b) then a:=a+2
  else if (a mod 3=0) and (b mod 2=0) and (a<>b) then begin
                                                        a:=a+2;
                                                        b:=b+3;
                                                      end
  else if (a mod 3=0) and (b>=a) then a:=a+2
  else if (a>=b) and (b mod 2=0) then b:=b+3;
  if kl1=1 then a:=d1;
  if kl2=1 then b:=d2;
  if a>b then min:=a
         else min:=b;
  writeln(min);
end.

var c:array[1..3000000]of byte;
a,b,da,db,d1,d2,i,kl1,kl2,min:longint;
begin
  readln(a,b);
  a:=a*2;
  b:=b*3;
  d1:=a;
  d2:=b;
  da:=(a div 3) div 2;
  db:=(b div 3) div 2;
  if da>db then min:=da
           else min:=db;
  while true do
  begin
    i:=i+1;
    if i>min then break;
    if a<b then begin
                  a:=a+2;
                  if (a<>b) and (a mod 3=0) and (c[a]=0)
                                       then begin
                                              min:=min+1;
                                              c[a]:=1;
                                            end;
                end
    else if b<a then begin
                       b:=b+3;
                       if (a<>b) and (b mod 2=0) and (c[b]=0)
                                         then begin
                                           min:=min+1;
                                           c[b]:=1;
                                          end;
                     end
    else if a=b then begin
                       a:=a+2;
                       if (a<>b) and (a mod 3=0) and (c[a]=0)
                                        then begin
                                               min:=min+1;
                                               c[a]:=1;
                                             end;
                     end
  end;
  if d1=a then begin
                 a:=2;
                 kl1:=1;
               end
  else if d2=b then begin
                 b:=3;
                 kl2:=1;
               end;
  if (a mod 3=0) and (b mod 2=0) and (a=b) then a:=a+2
  else if (a mod 3=0) and (b mod 2=0) and (a<>b) then begin
                                                        a:=a+2;
                                                        b:=b+3;
                                                      end
  else if (a mod 3=0) and (b>=a) then a:=a+2
  else if (a>=b) and (b mod 2=0) then b:=b+3;
  if kl1=1 then a:=d1;
  if kl2=1 then b:=d2;
  if a>b then min:=a
         else min:=b;
  writeln(min);
end.

uses math;
var n,m,mn,lik,t,kk,jj,minn:int64;
i,j:longint;
a:array [0..1000000] of int64;
ans,NN,MM:int64;

begin
readln(n,m);
nn:=n*2; T:=0;
mm:=m*3;
for i:=1 to 1000000 do
if (i mod 2=0)and(i mod 3=0) then begin inc(t);a[t]:=i;end;

minn:=maxlongint;
for i:=1 to t do
begin

if (a[i]<=nn)and(a[i]<=mm)and(nn>mm) then
                         begin minn:=abs(nn-mm);mm:=mm+3;end  else

if (a[i]<=nn)and(a[i]<=mm)and(nn<=mm)then
                         begin minn:=abs(nn-mm);nn:=nn+2;end;

end;
writelN(max(mm,nn));

end.

uses math;
var n,m,mn,lik,t,kk,jj,minn:int64;
i,j:longint;
a:array [0..10000] of int64;
ans,NN,MM:int64;

function step(st, lik:int64):int64;
var ans:int64;
J:LONGINT;
begin
ans:=1;
for j:=1 to lik do
ans:=ans*st;
step:=ans;
end;

begin
readln(n,m);
nn:=n*2; T:=0;
mm:=m*3;
for i:=1 to 22 do
for j:=1 to 14 do
begin
ans:=step(2,i)*step(3,j);
if (ans<=min(nn,mm)) then begin inc(t);a[t]:=ans;end;
end;

minn:=maxlongint;
for i:=1 to t do
begin

if (a[i]<=nn)and(a[i]<=mm)and(nn>=mm) then
                         begin minn:=abs(nn-mm);mm:=mm+3;end  else

if (a[i]<=nn)and(a[i]<=mm)and(nn<mm)then
                         begin minn:=abs(nn-mm);nn:=nn+2;end;

end;
writelN(max(mm,nn));

end.


John Doe decided that some mathematical object must be named after him. So he invented the Doe graphs. The Doe graphs are a family of undirected graphs, each of them is characterized by a single non-negative number — its order. We'll denote a graph of order k as D(k), and we'll denote the number of vertices in the graph D(k) as |D(k)|. Then let's define the Doe graphs as follows:  D(0) consists of a single vertex, that has number 1.  D(1) consists of two vertices with numbers 1 and 2, connected by an edge.  D(n) for n ≥ 2 is obtained from graphs D(n - 1) and D(n - 2). D(n - 1) and D(n - 2) are joined in one graph, at that numbers of all vertices of graph D(n - 2) increase by |D(n - 1)| (for example, vertex number 1 of graph D(n - 2) becomes vertex number 1 + |D(n - 1)|). After that two edges are added to the graph: the first one goes between vertices with numbers |D(n - 1)| and |D(n - 1)| + 1, the second one goes between vertices with numbers |D(n - 1)| + 1 and 1. Note that the definition of graph D(n) implies, that D(n) is a connected graph, its vertices are numbered from 1 to |D(n)|.   The picture shows the Doe graphs of order 1, 2, 3 and 4, from left to right. John thinks that Doe graphs are that great because for them exists a polynomial algorithm for the search of Hamiltonian path. However, your task is to answer queries of finding the shortest-length path between the vertices ai and bi in the graph D(n).A path between a pair of vertices u and v in the graph is a sequence of vertices x1, x2, ..., xk (k > 1) such, that x1 = u, xk = v, and for any i (i < k) vertices xi and xi + 1 are connected by a graph edge. The length of path x1, x2, ..., xk is number (k - 1).

The first line contains two integers t and n (1 ≤ t ≤ 105; 1 ≤ n ≤ 103) — the number of queries and the order of the given graph. The i-th of the next t lines contains two integers ai and bi (1 ≤ ai, bi ≤ 1016, ai ≠ bi) — numbers of two vertices in the i-th query. It is guaranteed that ai, bi ≤ |D(n)|. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

For each query print a single integer on a single line — the length of the shortest path between vertices ai and bi. Print the answers to the queries in the order, in which the queries are given in the input.

program graph;
const mx=82;
var
     t,n,i,j:longint;
     x,y:int64;
     g,a1,an,b1,bn,c:array[0..82] of longint;
     f,a,b:array[0..82] of int64;
     qa,qb:array[0..82] of boolean;

procedure swap(var x,y:int64);
var  tmp:int64;
begin
     tmp:=x; x:=y; y:=tmp;
end;

function min(x,y:int64):int64;
begin
     if x<=y then exit(x) else exit(y);
end;

begin
     readln(t,n);
     f[1]:=1; f[2]:=1;
     for i:=3 to mx do f[i]:=f[i-1]+f[i-2];
     for i:=2 to mx do g[i]:=g[i-1]+1-(i and 1);
     while t>0 do
     begin
          readln(x,y);
          j:=-1;
          if x>y then swap(x,y);
          for i:=min(n+1,mx) downto 1 do
          begin
               if (j<0)and(x<=f[i])and(y>f[i]) then j:=i;
               a[i]:=x;
               if (x>f[i]) then
               begin
                    x:=x-f[i]; qa[i-1]:=true;
               end else qa[i-1]:=false;
               b[i]:=y;
               if (y>f[i]) then
               begin
                    y:=y-f[i]; qb[i-1]:=true;
               end else qb[i-1]:=false;
          end;
          for i:=2 to min(n+1,mx) do
          begin
             if (a[i]<=f[i]) then
             begin
                 a1[i]:=min(a1[i-1],an[i-1]+2);
                 an[i]:=min(a1[i-1],an[i-1])+1+g[i-2];
                 if i>j then
                 begin
                     c[i]:=c[i-1];
                     if (not qa[i]) and (not qb[i]) then
                        c[i]:=min(c[i],min(a1[i-1]+2+bn[i-1],an[i-1]+2+b1[i-1]));
                 end;
                 if i=j then c[i]:=min(a1[i-1],an[i-1])+1+b1[i-2];
             end else
             begin
                 a1[i]:=a1[i-2]+1;
                 an[i]:=an[i-2];
                 if i>j then c[i]:=c[i-1];
             end;
             if b[i]<=f[i] then
             begin
                 b1[i]:=min(b1[i-1],bn[i-1]+2);
                 bn[i]:=min(b1[i-1],bn[i-1])+1+g[i-2];
             end else
             begin
                 b1[i]:=b1[i-2]+1;
                 bn[i]:=bn[i-2];
             end;
          end;
          writeln(c[min(n+1,mx)]);
          dec(t);
     end;
end.

program problem3;

var fib: array[0..78] of int64;
    arr: array[ 1..78, 1..4 ] of longWord;
    id: array[ 1..78, 0..1 ] of int64;

function min( a, b: longWord ): longWord;
begin
  if ( a < b ) then
    min := a
  else
    min := b;
end;

function minPath( a, b: int64; n: longWord ): longWord;
var res, k: longWord;
    i: longWord;
    minAB, maxAB: int64;
begin
  if ( a > b ) then
  begin
    maxAB := a;
    minAB := b;
  end
  else
  begin
    maxAB := b;
    minAB := a;
  end;

  if ( a = b ) then
  begin
    minPath := 0;
    exit;
  end
  else if ( n = 1 ) then
  begin
    minPath := 1;
    exit;
  end
  else if ( minAB = 1 ) and ( maxAB = fib[n] ) then
  begin
    minPath := ( n + 1 ) div 2;
    exit;
  end;

  if ( minAB = 1 ) and ( maxAB = id[n][0] ) then
    i := 1
  else if ( minAB = 1 ) and ( maxAB = id[n][1] ) then
    i := 2
  else if ( maxAB = fib[n] ) and ( minAB = id[n][0] ) then
    i := 3
  else if ( maxAB = fib[n] ) and ( minAB = id[n][1] ) then
    i := 4
  else
    i := 0;

  if ( i <> 0 ) and ( arr[n][i] <> 0 ) then
  begin
    minPath := arr[n][i];
    exit;
  end;

  if ( minAB = 1 ) then
  begin
    if ( maxAB > fib[n-1] ) then
      res := minPath( ( maxAB - fib[n-1] ), 1, (n-2) ) + 1
    else
    begin
      res := minPath( maxAB, 1,        (n-1) );
      k   := minPath( maxAB, fib[n-1], (n-1) ) + 2;

      res := min( res, k );
    end;
  end
  else if ( a <= fib[n-1] ) and ( b <= fib[n-1] ) then
  begin
    res := minPath( a, b, (n-1) );
    k := minPath( a, 1, (n-1) ) + minPath( b, fib[n-1], (n-1) ) + 2;
    res := min( res, k );
    k := minPath( b, 1, (n-1) ) + minPath( a, fib[n-1], (n-1) ) + 2;
    res := min( res, k );
  end
  else if ( maxAB = fib[n] ) then
  begin
    if ( minAB > fib[n-1] ) then
      res := minPath( ( minAB - fib[n-1] ), fib[n-2], (n-2) )
    else
    begin
      res := minPath( minAB, 1,        (n-1) );
      k   := minPath( minAB, fib[n-1], (n-1) );

      res := min( res, k ) + 1 + minPath( 1, fib[n-2], (n-2) );
    end;
  end
  else if ( a > fib[n-1] ) and ( b > fib[n-1] ) then
    res := minPath( ( a - fib[n-1] ), ( b - fib[n-1] ), (n-2) )
  else
  begin
    res := minPath( minAB, 1,        (n-1) );
    k   := minPath( minAB, fib[n-1], (n-1) );
    res := min( res, k );

    k := minPath( ( maxAB - fib[n-1] ), 1, (n-2) );
    res := res + k + 1;
  end;

  if ( i <> 0 ) then
    arr[n][i] := res;

  minPath := res;
end;

var t, n, i, j: longWord;
    a, b, ap, bp: int64;

begin
  fib[0] := 1;
  fib[1] := 2;
  for i := 2 to 78 do
    fib[i] := fib[i-1] + fib[i-2];

  readln( t, n );

  n := min( n, 78 );

  for i := 1 to t do
  begin
    fillchar( arr, sizeOf(arr), 0 );

    readln( a, b );

    ap := a;
    bp := b;
    for j := n downTo 1 do
    begin
      if ( ap > fib[j] ) then
        ap := ap - fib[j];
      if ( bp > fib[j] ) then
        bp := bp - fib[j];

      id[j][0] := ap;
      id[j][1] := bp;
    end;

    writeln( minPath( a, b, n ) );
  end;
end.