#include <bits/stdc++.h>
using namespace std;
const int lim = 2e4 + 4;
vector<int> adj[lim];
int ans = 0;
vector<bool> vis(lim, false);
vector<int> dist(lim);
vector<int> parent(lim, -1);
void bfs(int s, int e) {
  queue<int> q;
  q.push(s);
  vis[s] = true;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int it : adj[v]) {
      if (!vis[it]) {
        vis[it] = true;
        q.push(it);
        dist[it] = dist[v] + 1;
        parent[it] = v;
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < lim; ++i) {
    if (i >= 2) adj[i].push_back(i - 1);
    if (i * 2 < lim) adj[i].push_back(2 * i);
  }
  bfs(n, m);
  cout << dist[m] << endl;
  return 0;
}
