#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e4 + 10;
int dis[maxN];
int main() {
  int n, m;
  cin >> n >> m;
  queue<int> q;
  q.push(n);
  dis[n] = 0;
  while (q.size()) {
    int v = q.front();
    q.pop();
    int u = 2 * v;
    if (u <= 1e4 && !dis[u]) {
      q.push(u);
      dis[u] = dis[v] + 1;
    }
    u = v - 1;
    if (u >= 1 && !dis[u]) {
      q.push(u);
      dis[u] = dis[v] + 1;
    }
  }
  cout << dis[m] << endl;
  return 0;
}
