#include using namespace std; typedef long long ll; int main() { int n, q; cin >> n >> q; while(q--){ ll s, t; cin >> s >> t; int ans = 0; for(int i = 0; i <= 60; i++){ if(((s >> i) & 1) && s + (1ll << i) <= t){ s += (1ll << i); ans++; } } for(int i = 60; i >= 0; i--){ if(s + (1ll << i) <= t){ s += (1ll << i); ans++; } } cout << ans << endl; } }