var
n,m,t,i:longint;
ans:array[0..10000] of longint;
procedure add(k:longint);
var
i:longint;
begin
inc(ans[1],k);
i:=1;
while ans[i]>=10000 do begin
inc(ans[i+1],ans[i] div 10000);
ans[i]:=ans[i] mod 10000;
inc(i);
end;
if i>t then t:=i;
end;
procedure cheng;
var
i:longint;
begin
for i:=1 to t do ans[i]:=ans[i]*2;
for i:=1 to t do
if ans[i]>=10000 then begin
inc(ans[i+1],ans[i] div 10000);
ans[i]:=ans[i] mod 10000;
end;
if ans[t+1]>0 then inc(t);
end;
function dfs(i:longint):int64;
begin
if i<m then ans[1]:=i*2-1
else begin
dfs(i-m+2);
cheng;
add((m-2)*2-1);
end;
end;
begin
assign(input,'ionah.in');reset(input);
assign(output,'ionah.out');rewrite(output);
read(m,n);t:=1;
dfs(n);
for i:=1 to t do
if ans[i]>=10000 then begin
inc(ans[i+1],ans[i] div 10000);
ans[i]:=ans[i] mod 10000;
end;
if ans[t+1]>0 then inc(t);
write(ans[t]);
for i:=t-1 downto 1 do begin
if ans[i]=0 then write('0000');
if (ans[i]>0)and(ans[i]<10) then write('000',ans[i]);
if (ans[i]>10)and(ans[i]<100) then write('00',ans[i]);
if (ans[i]>100)and(ans[i]<1000) then write('0',ans[i]);
if (ans[i]>1000) then write(ans[i]);
end;
writeln;
close(input);close(output);
end.