#include <bits/stdc++.h>
using namespace std;
int from, to;
bool vis[20002];
int yo2() {
  queue<pair<int, int> > q;
  q.push(make_pair(from, 0));
  while (!q.empty()) {
    pair<int, int> now = q.front();
    vis[now.first] = true;
    q.pop();
    if (now.first == to) return now.second;
    if (now.first > 0 && vis[now.first - 1] == false)
      q.push(make_pair(now.first - 1, now.second + 1));
    if (now.first <= to && now.first > 0 && vis[now.first * 2] == false)
      q.push(make_pair(now.first * 2, now.second + 1));
  }
}
int main() {
  cin >> from >> to;
  cout << yo2();
  return 0;
}
