#include <bits/stdc++.h>
using namespace std;
class Graph {
 public:
  int V;
  list<pair<int, int> >* edges;
  Graph(int V) {
    this->V = V;
    edges = new list<pair<int, int> >[V];
  }
  void addEdge(int u, int v, int w = 1) { edges[u].push_back({v, w}); }
  int d(int src, int end);
};
int Graph::d(int src, int end) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  vector<int> dist(V, 0x3f3f3f3f);
  dist[src] = 0;
  pq.push(make_pair(0, src));
  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    list<pair<int, int> >::iterator it;
    for (it = edges[u].begin(); it != edges[u].end(); ++it) {
      int v = it->first;
      int weight = it->second;
      if (dist[v] > dist[u] + weight) {
        dist[v] = dist[u] + weight;
        pq.push(make_pair(dist[v], v));
      }
    }
  }
  std::cout << dist[end];
}
int main() {
  int n, m, count = 0;
  scanf("%d %d", &n, &m);
  if (m < n) {
    std::cout << n - m;
  } else if (m > n) {
    Graph g(10003);
    g.addEdge(1, 2);
    for (int i = 2; i <= 10000; ++i) {
      if ((i * 2) < 10001) g.addEdge(i, i * 2);
      g.addEdge(i, i - 1);
    }
    g.d(n, m);
  } else if (m == n) {
    std::cout << 0;
  }
  return 0;
}
