import sys input = sys.stdin.readline N, Q = map(int, input().split()) for _ in range(Q): s, t = map(int, input().split()) res = 0 while s < t: for i in range(N, -1, -1): if s % pow(2, i) == 0 and s + pow(2, i) <= t: s += pow(2, i) break res += 1 print(res)