from sys import stdin n, q, *indata = map(int, stdin.read().split()) offset = 0 for i in range(q): s, t = indata[offset + 2*i],indata[offset + 2*i+1] ans = 0 if s == 0: check = True while t > 0: kari = t & (-t) t -= kari ans += 1 else: check = True while check: kari = s & (-s) if s + kari <= t: s += kari ans += 1 else: check = False check = True while t > s: kari = t & (-t) t -= kari ans += 1 print("{}".format(ans))