mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline N, Q = map(int, input().split()) for _ in range(Q): s, t = map(int, input().split()) ans = 0 while t != s: if s: x = s & (-s) else: x = 1 << N y = 1 << ((t-s).bit_length() - 1) s += min(x, y) ans += 1 print(ans) if __name__ == '__main__': main()