#include "atcoder/all" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const long long int INF = numeric_limits::max() / 4; const int inf = numeric_limits::max() / 4; const long long int MOD1000000007 = 1000000007; const long long int MOD998244353 = 998244353; const double MATH_PI = 3.1415926535897932; template inline void chmin(T1 &a, const T2 &b) { if (a > b) a = b; } template inline void chmax(T1 &a, const T2 &b) { if (a < b) a = b; } #define lint long long int #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define rep(i, n) for(int i=0;i<(int)(n);i++) #define VI vector #define VLL vector #define VC vector #define VB vector #define PI pair #define PLL pair #define VPI vector> #define VPLL vector> #define VVI vector> #define VVPI vecor>> #define VVPILL vector>> #define SUM(v) accumulate(ALL(v), 0LL) #define MIN(v) *min_element(ALL(v)) #define MAX(v) *max_element(ALL(v)) int main() { lint n, q; cin >> n >> q; vector po2(n + 1, 1); for (int i = 1; i <= n; i++) { po2[i] *= po2[i - 1] * 2; } for (int i = 0; i < q; i++) { // cerr << "i = " << i << endl; lint s, t; cin >> s >> t; lint ans = 0; while (true) { for (lint j = n; j >= 0; j--) { if (s % po2[j] == 0 and s + po2[j] <= t) { ans++; s += po2[j]; break; } } if (s == t) { cout << ans << endl; break; } } } return 0; }