#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> top;
queue<pair<int, int> > q;
vector<int> num;
int main() {
  scanf("%d %d", &n, &m);
  q.push(make_pair(n, 0));
  num.resize(10001, 999999);
  while (!q.empty()) {
    top = q.front();
    q.pop();
    if (num[top.first] > top.second) {
      num[top.first] = top.second;
      if (top.first - 1 >= 0) {
        q.push(make_pair(top.first - 1, top.second + 1));
      }
      if (top.first * 2 <= 10000) {
        q.push(make_pair(top.first * 2, top.second + 1));
      }
    }
    if (top.first == m) break;
  }
  printf("%d\n", num[m]);
}
