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: x = s & (-s) y = 1 << ((t-s).bit_length() - 1) assert min(x, y) > 0 s += min(x, y) ans += 1 print(ans) if __name__ == '__main__': main()