#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 * 2 + 5;
int n, m, ans;
queue<pair<int, int> > q;
bool visited[N];
int main() {
  scanf("%d%d", &n, &m);
  q.push({n, 0});
  while (!q.empty()) {
    int num = q.front().first;
    int step = q.front().second;
    q.pop();
    if (num == m) {
      ans = step;
      break;
    }
    if ((!visited[num - 1]) && (num - 1 > 0)) {
      q.push({num - 1, step + 1});
      visited[num - 1] = true;
    }
    if ((num * 2 <= m * 2) && (!visited[num * 2])) {
      q.push({num * 2, step + 1});
      visited[num * 2] = true;
    }
  }
  printf("%d\n", ans);
  return 0;
}
