#include <bits/stdc++.h>
using namespace std;
vector<int> bfs(const vector<vector<int>>& graph, int begin) {
  const int None = -1;
  vector<int> d(graph.size(), None);
  d[begin] = 0;
  vector<int> vertices = {begin};
  int cur_d = 1;
  while (not vertices.empty()) {
    vector<int> s_ver;
    for (auto v : vertices) {
      for (auto u : graph[v]) {
        if (d[u] == None) {
          d[u] = cur_d;
          s_ver.push_back(u);
        }
      }
    }
    vertices = s_ver;
    cur_d++;
  }
  return d;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> graph(max(n, m) * 2 + 1);
  for (int i = 1; i < max(n, m) * 2 + 1; i++) {
    if (i - 1 > 0) {
      graph[i].push_back(i - 1);
    }
    if (i * 2 <= max(n, m) * 2) {
      graph[i].push_back(i * 2);
    }
  }
  cout << bfs(graph, n)[m] << endl;
  return 0;
}
