#include <bits/stdc++.h>
using namespace std;
deque<int> v;
int ans[200001];
int main() {
  int n, m;
  cin >> n >> m;
  v.push_back(n);
  for (int i = 0; i < 200000; i++) ans[i] = 1e9;
  ans[n] = 0;
  while (v.size() != 0) {
    int x = v[0];
    v.pop_front();
    if (2 * x < 200000 && ans[2 * x] > ans[x] + 1) {
      v.push_back(2 * x);
      ans[2 * x] = ans[x] + 1;
    }
    if (x > 0 && ans[x - 1] > ans[x] + 1) {
      v.push_back(x - 1);
      ans[x - 1] = ans[x] + 1;
    }
  }
  cout << ans[m] << endl;
  return 0;
}
