#include <bits/stdc++.h>
using namespace std;
int N, M;
bool visited[100001];
queue<pair<int, int>> q;
void BFS() {
  q.push({N, 0});
  while (!q.empty()) {
    int x = q.front().first;
    int cnt = q.front().second;
    q.pop();
    if (x == M) {
      cout << cnt;
      return;
    }
    if (!visited[x * 2] && x <= M) {
      q.push({x * 2, cnt + 1});
      visited[x * 2] = true;
    }
    if (x >= 1) {
      if (!visited[x - 1]) {
        q.push({x - 1, cnt + 1});
        visited[x - 1] = true;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> N >> M;
  visited[N] = true;
  BFS();
  return 0;
}
