from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,Q = map(int,input().split()) def solve(s,t): S = [] T = [] for i in range(60): if (s>>i)&1: S.append(i) if (t>>i)&1: T.append(i) if len(S) == 0: return len(T) while S[-1]==T[-1]: S.pop() T.pop() if len(S)==0: break if len(S) == 0: return len(T) cost = T[-1] - S[0] - (len(S) - 1) cost += (len(T)-1) return cost for _ in range(Q): s,t = map(int,input().split()) print(solve(s,t),flush=True)