#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
void TimeExecution() {
  cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
long long n, m;
long long temp;
long long d;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  if (n >= m)
    cout << n - m;
  else {
    if (m % 2 == 0)
      temp = m;
    else {
      temp = m + 1;
      d = 1;
    }
    while (temp > n) {
      if (temp % 2 == 0)
        temp /= 2;
      else {
        temp++;
      }
      d++;
    }
    d = d + (n - temp);
    cout << d;
  }
  return 0;
}
