#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define ff(i,s,f) for(int i=s;i<f;i++)
#define fb(i,s,f) for(int i=(s)-1;i>=f;i--)
#define ffi(i,s,f) for(int i=s;i<=f;i++)
#define fbi(i,s,f) for(int i=s;i>=f;i--)
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,int) sort(a.begin(),a.end(),greater<int>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define ub(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;

const int maxn=2e5+10;

int n,m;
vector<int> segtd[4*maxn];
vector<int> segtu[4*maxn];
int d[maxn];
int u[maxn];

void build(int *a,vector<int> *segt,int node=1,int l=0,int r=n-1){
    if(l==r){
        segt[node]={a[l]};
        return;
    }
    int mid=l+(r-l)/2;
    build(a,segt,2*node,l,mid);
    build(a,segt,2*node+1,mid+1,r);
    merge(segt[2*node].begin(),segt[2*node].end(),
          segt[2*node+1].begin(),segt[2*node+1].end(),
          back_inserter(segt[node]));
}

int iter=0;

int query(vector<int> *segt,int tl,int tr,int x,int node=1,int l=0,int r=n-1){
    iter++;
    if(tl<=l && r<=tr){
        return upper_bound(segt[node].begin(),segt[node].end(),x)-segt[node].begin();
    }
    int mid=l+(r-l)/2;
    int ret=0;
    if(tl<=mid) ret+=query(segt,tl,tr,x,2*node,l,mid);
    if(tr>mid) ret+=query(segt,tl,tr,x,2*node+1,mid+1,r);
    return ret; 
}

void solve(){
    cin>>n>>m;
    if(n>100) return;
    m=200000;
    n=200000;
    mt19937 rng(3423235);
    for(int i=0;i<n;i++){
        //cin>>d[i]>>u[i];
        d[i]=rng()%1000000001;
        u[i]=rng()%1000000001;
        if(d[i]>u[i]) swap(d[i],u[i]);
    }
    build(d,segtd);
    build(u,segtu);
    while(m--){
        int l,r,x;
        //cin>>l>>r>>x;
        l=rng()%n+1;
        r=rng()%n+1;
        if(l>r) swap(l,r);
        x=rng()%1000000001;
        l--; r--;
        cout<<query(segtd,l,r,x)-query(segtu,l,r,x-1)<<"\n";
    }
    cout<<iter<<"\n";
}

int main(){
    ios;
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}