from functools import lru_cache n, q = map(int, input().split()) @lru_cache def cost(l, r, i): if i == 0: return r - l else: cnt = r // (1 << i) - (l - 1) // (1 << i) if cnt < 2: return cost(l, r, i - 1) else: u = ((l + (1 << i) - 1) // (1 << i)) * (1 << i) v = (r // (1 << i)) * (1 << i) return cost(l, u, i - 1) + (v - u) // (1 << i) + cost(v, r, i - 1) for _ in range(q): s, t = map(int, input().split()) print(cost(s, t, n))