import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { sb.append(getCount(sc.nextLong(), sc.nextLong())).append("\n"); } System.out.print(sb); } static int getCount(long start, long end) { long mid = getMid(start, end); return getPop(mid - start) + getPop(end - mid); } static long getMid(long start, long end) { long ans = 0; for (int i = 60; i >= 0; i--) { if ((end & (1L << i)) == 0) { continue; } ans += (1L << i); if ((start & (1L << i)) == 0) { break; } } return ans; } static int getPop(long x) { long pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return (int)pop; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }