#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def main(): def f(l,r): l += 2**n r += 2**n res = 0 while l < r: if l & 1: res +=1 l += 1 if r & 1: r -= 1 res += 1 l >>= 1 r >>= 1 return res n,q = LI() for _ in range(q): l,r = LI() print(f(l,r)) return if __name__ == "__main__": main()