#include <bits/stdc++.h>
using namespace std;
vector<int> adj[20010];
int dist[20010], pos[20010];
void BFS(int st) {
  dist[st] = 0;
  queue<int> bfsq;
  bfsq.push(st);
  while (!bfsq.empty()) {
    int vrh = bfsq.front();
    bfsq.pop();
    pos[vrh] = 1;
    for (auto x : adj[vrh]) {
      if (!pos[x]) {
        dist[x] = dist[vrh] + 1;
        bfsq.push(x);
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= 20010; i++) {
    if (i - 1 >= 0) {
      adj[i].push_back(i - 1);
    }
    if (2 * i <= 2 * m) {
      adj[i].push_back(2 * i);
    }
  }
  BFS(n);
  printf("%d", dist[m]);
  return 0;
}
