N,M=map(int,input().split()) ans = 0 while M>2: ans += M M+=M&1 M>>=1 N-=1 ans += N+M-1 print(ans)