N,K = map(int,input().split()) ans = 0 R = N-K while(N): N >>= 1 ans += N while(K): K >>= 1 ans -= K while(R): R >>= 1 ans -= R print(ans)