#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, z, i, cr;
  cin >> a >> z;
  long long int size = max(z + 1, 2 * a);
  long long int dp[size + 1];
  for (i = 0; i <= size; i++) dp[i] = INT_MAX;
  dp[z] = 0;
  queue<long long int> vis;
  vis.push(z);
  if (a > z)
    cout << a - z;
  else {
    while (dp[a] == INT_MAX) {
      cr = vis.front();
      vis.pop();
      if (cr % 2 == 0 && dp[cr / 2] == INT_MAX) {
        dp[cr / 2] = dp[cr] + 1;
        vis.push(cr / 2);
      }
      if (cr + 1 <= size && dp[cr + 1] == INT_MAX) {
        dp[cr + 1] = dp[cr] + 1;
        vis.push(cr + 1);
      }
    }
    cout << dp[a];
  }
  return 0;
}
