#include using namespace std; using ll = long long; int main(void) { ll N, K; cin >> N >> K; int ans = 0; ll R = N - K; while (N) { N >>= 1; ans += N; } while (K) { K >>= 1; ans -= K; } while (R) { R >>= 1; ans -= R; } cout << ans << endl; return 0; }