#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int steps = 0;
  if (n >= m)
    steps = n - m;
  else {
    int temp = m;
    while (temp != n) {
      if (temp > n) {
        if (temp % 2 == 0) {
          temp /= 2;
          steps++;
        } else {
          temp += 1;
          if (temp != n) {
            temp /= 2;
            steps += 2;
          } else
            steps++;
        }
      } else {
        temp += 1;
        steps++;
      }
    }
  }
  cout << steps;
  return 0;
}
