//Prilikom rjepavanja zadatka korišten je algoritam: 

//ZAD4: Segment tree + lazy propagation, predstaviti cevape kao niz jedinica i nula, svaka operacija invertuje nule i jedinice u podnizu, izbrojati broj jedinica u podnizu

#include <iostream>
#include <algorithm>

int a[100010], segTree[400010], lazy[400010] = { 0 };

void construct(int low, int high, int pos)
{
    if (low == high)
    {
        segTree[pos] = a[low];
        return;
    }

    int mid = low + (high - low) / 2;

    construct(low, mid, pos * 2 + 1);
    construct(mid + 1, high, pos * 2 + 2);

    segTree[pos] = segTree[pos * 2 + 1] + segTree[pos * 2 + 2];
}

int query(int qlow, int qhigh, int low, int high, int pos)
{
    if (lazy[pos] % 2 == 1)
            segTree[pos] = (high - low + 1) - segTree[pos];
    
    if (low != high)
    {
        lazy[pos * 2 + 1] += lazy[pos];
        lazy[pos * 2 + 2] += lazy[pos];
    }

    lazy[pos] = 0;

    if (low > qhigh || high < qlow)
        return 0;

    if (qlow <= low && high <= qhigh)
    {
        return segTree[pos];
    }

    int mid = low + (high - low) / 2;

    return query(qlow, qhigh, low, mid, pos * 2 + 1) + query(qlow, qhigh, mid + 1, high, pos * 2 + 2);
}

void update(int qlow, int qhigh, int low, int high, int pos)
{
    if (lazy[pos] % 2 == 1)
        segTree[pos] = (high - low + 1) - segTree[pos];

    if (low != high)
    {
        lazy[pos * 2 + 1] += lazy[pos];
        lazy[pos * 2 + 2] += lazy[pos];
    }

    lazy[pos] = 0;

    if (low > qhigh || high < qlow)
        return;

    if (qlow <= low && high <= qhigh)
    {
        ++lazy[pos];
        if (lazy[pos] % 2 == 1)
            segTree[pos] = (high - low + 1) - segTree[pos];

        if (low != high)
        {
            lazy[pos * 2 + 1] += lazy[pos];
            lazy[pos * 2 + 2] += lazy[pos];
        }

        lazy[pos] = 0;

        return;
    }

    int mid = low + (high - low) / 2;

    update(qlow, qhigh, low, mid, pos * 2 + 1);
    update(qlow, qhigh, mid + 1, high, pos * 2 + 2);

    segTree[pos] = segTree[pos * 2 + 1] + segTree[pos * 2 + 2];
}

int main() {
    int n, m, l[100010], r[100010];
    std::cin >> n >> m;

    construct(0, n - 1, 0);

    for (int i = 0; i < m; ++i) {
        std::cin >> l[i] >> r[i];
        --l[i]; --r[i];
        
        std::cout << query(l[i], r[i], 0, n - 1, 0) << "\n";

        update(l[i], r[i], 0, n - 1, 0);
    }
}