#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 1e5;
vector<pair<int, int> > v[N];
bool vis[N];
int d[N];
int main() {
  int n, m;
  cin >> n >> m;
  queue<int> q;
  q.push(n);
  vis[n] = 1;
  while (!q.empty()) {
    int w = q.front();
    if (w == m) {
      cout << d[w];
      return 0;
    }
    q.pop();
    int k1 = w * 2, k2 = w - 1;
    if (!vis[k1] && k1 <= 1e4 && k1 > 0) {
      vis[k1] = 1;
      d[k1] = d[w] + 1;
      q.push(k1);
    }
    if (!vis[k2] && k2 > 0 && k2 <= 1e4) {
      vis[k2] = 1;
      d[k2] = d[w] + 1;
      q.push(k2);
    }
  }
  return 0;
}
