#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, Q;
  cin >> N >> Q;

  while(Q--) {
    ll L, R;
    cin >> L >> R;

    ll ans = 0;
    auto rec = [&](auto rec, ll l, ll r) -> void {
      if(L <= l && r <= R) {
        ans++;
        return;
      }
      if(r - l == 1) { return; }
      ll m = (l + r) / 2;
      if(m <= R) { rec(rec, m, r); }
      if(L <= m) { rec(rec, l, m); }
    };
    rec(rec, 0, 1LL << N);

    cout << ans << "\n";
  }
}