#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
queue<int> q;
int used[100001];
int d[100001];
int x, n, m;
void bfs(int s) {
  q.push(s);
  d[s] = 0;
  used[s] = 1;
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    x = 2 * top;
    if (x <= 10001 && !used[x]) {
      q.push(x);
      used[x] = 1;
      d[x] = d[top] + 1;
      if (x == m) return;
    }
    x = top - 1;
    if (x > 0 && !used[x]) {
      q.push(x);
      used[x] = 1;
      d[x] = d[top] + 1;
      if (x == m) return;
    }
  }
}
int main() {
  cin >> n >> m;
  bfs(n);
  cout << d[m] << endl;
  cin.sync();
  cin.get();
  return 0;
}
