#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100, INF = 0x3f3f3f3f;
int n, m;
vector<int> grafo[MAXN];
int dist[MAXN];
void djikstra() {
  dist[n] = 0;
  priority_queue<pair<int, int> > fila;
  fila.push({-dist[n], n});
  while (!fila.empty()) {
    int a = fila.top().second;
    fila.pop();
    for (int i = 0; i < grafo[a].size(); i++) {
      int v = grafo[a][i];
      if (dist[v] > dist[a] + 1) {
        dist[v] = dist[a] + 1;
        fila.push({-dist[v], v});
      }
    }
  }
}
int main() {
  cin >> n >> m;
  grafo[1].push_back(2);
  for (int i = 2; i <= 2 * max(n, m); i++) {
    grafo[i].push_back(i - 1);
    grafo[i].push_back(2 * i);
  }
  memset(dist, INF, sizeof dist);
  djikstra();
  cout << dist[m] << endl;
}
