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 n2 = 1L << n; PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { long ans = 0; long now = s[i]; while (now < t[i]) { long v = Long.lowestOneBit(now); if (v == 0) { v = n2; } while (v > 0) { if (now % v == 0 && now + v <= t[i]) { ans++; now += v; break; } v /= 2; } } pw.println(ans); } pw.flush(); } }