using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); static long[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, q) = ((int)c[0], (int)c[1]); var query = NArr(q); var ans = new List(q); foreach (var que in query) { var s = Pop(que[0]); var t = Pop(que[1]); while (s.Count > 0 && t.Count > 0 && s[0] == t[0]) { s.RemoveAt(0); t.RemoveAt(0); } var ai = 0; while (true) { if (s.Count == 0 || (s.Count == 1 && s[0] == t[0])) break; ++ai; var cur = s[^1]; s.RemoveAt(s.Count - 1); while (s.Count > 0 && s[^1] == cur + 1) { ++cur; s.RemoveAt(s.Count - 1); } s.Add(cur + 1); } ans.Add(ai + t.Count - s.Count); } WriteLine(string.Join("\n", ans)); } static List Pop(long a) { var ans = new List(); var pos = 0; while (a > 0) { if (a % 2 == 1) ans.Add(pos); a >>= 1; ++pos; } ans.Reverse(); return ans; } }