#include <bits/stdc++.h>
using namespace std;
class Graph {
  int n;
  vector<int>* adj;

 public:
  Graph(int v) {
    n = v;
    adj = new vector<int>[n + 1];
  }
  void addEdge(int a, int b) { adj[a].push_back(b); }
  int answer(int N, int m) {
    vector<int> dist(n + 1, -1);
    queue<int> Q;
    dist[N] = 0;
    Q.push(N);
    while (!Q.empty()) {
      int par = Q.front();
      Q.pop();
      for (int x : adj[par]) {
        if (dist[x] == -1) {
          dist[x] = 1 + dist[par];
          Q.push(x);
        }
      }
    }
    return dist[m];
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  Graph G(40004);
  for (int i = 1; i <= max(2 * m, n); i++) {
    G.addEdge(i, i - 1);
    if (i < m) {
      G.addEdge(i, 2 * i);
    }
  }
  cout << G.answer(n, m) << endl;
  return 0;
}
