#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, ans = 0;
  cin >> n >> m;
  if (n > m)
    cout << n - m;
  else {
    while (m > n) {
      if (m % 2 == 0) {
        m /= 2;
        ans++;
      } else {
        m++;
        ans++;
      }
    }
    cout << ans + n - m;
  }
}
