#include <bits/stdc++.h>
using namespace std;
int mark[100000];
int main(int argc, char const *argv[]) {
  queue<pair<int, int> > q;
  int n, m;
  cin >> n >> m;
  q.push(make_pair(n, 0));
  mark[n] = 1;
  pair<int, int> pr;
  int cnt = 0;
  while (1) {
    pr = q.front();
    q.pop();
    int a = pr.first;
    int b = pr.second;
    if (a << 1 == m) {
      cout << b + 1 << endl;
      break;
    }
    if (a - 1 == m) {
      cout << b + 1 << endl;
      break;
    }
    if (a << 1 < 20000 && mark[a << 1] == 0) {
      q.push(make_pair(a << 1, b + 1));
      mark[a << 1] = 1;
    }
    if (a - 1 > 0 && mark[a - 1] == 0) {
      q.push(make_pair(a - 1, b + 1));
      mark[a - 1] = 1;
    }
  }
  return 0;
}
