#include using namespace std; struct Node { int num; int step; }; const int N = 1010; int n, m; queue q; int st[N]; void bfs() { q.push({n, 0}); while (q.size()) { auto x = q.front(); q.pop(); if (x.num == m) { printf("%d\n", x.step); break; } if (!st[x.num + 1]) { q.push({x.num + 1, x.step + 1}); st[x.num + 1] = 1; } if (!st[x.num - 1]) { q.push({x.num - 1, x.step + 1}); st[x.num - 1] = 1; } if (!st[x.num * 2]) { q.push({x.num * 2, x.step + 1}); st[x.num * 2] = 1; } } } int main() { cin >> n >> m; bfs(); return 0; }