import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int q = Integer.parseInt(sa[1]); long[] s = new long[q]; long[] t = new long[q]; for (int i = 0; i < q; i++) { sa = br.readLine().split(" "); s[i] = Long.parseLong(sa[0]); t[i] = Long.parseLong(sa[1]); } br.close(); long[] b = new long[n + 1]; b[0] = 1; for (int i = 1; i < b.length; i++) { b[i] = b[i - 1] * 2; } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { long ans = 0; long now = s[i]; while (now < t[i]) { for (int j = n; j >= 0; j--) { if (now % b[j] == 0 && now + b[j] <= t[i]) { ans++; now += b[j]; break; } } } pw.println(ans); } pw.flush(); } }