#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>
using namespace std;
#ifdef DEBUG
//#define LOCAL_INPUT_FILE
#else
//#define USE_FILE_IO
#endif
#ifdef USE_FILE_IO
#define INPUT_FILE "input.txt"
#define OUTPUT_FILE "output.txt"
#define cin ____cin
#define cout ____cout
ifstream cin(INPUT_FILE);
ofstream cout(OUTPUT_FILE);
#else
#ifdef LOCAL_INPUT_FILE
#define cin ____cin
ifstream cin("input.txt");
#endif
#endif
const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7;
const long double eps = 1e-8;
inline void raiseError(string errorCode) {
cerr << "Error : " << errorCode << endl;
exit(42);
}
int block = 200;
struct Query {
int l, r, idx;
inline pair<int, int> toPair() const {
return make_pair(l / block, ((l / block) & 1) ? -r : +r);
}
};
inline bool operator<(const Query &a, const Query &b) {
return a.toPair() < b.toPair();
}
signed main() {
#ifndef USE_FILE_IO
ios_base::sync_with_stdio(false);
#endif
mt19937 rnd(42);
int n, m, k; cin >> n >> m; k = rnd() % 1048576;
vector<int> p(n+1);
for (int i = 0; i < n; i++) {
int val = rnd() % 1048576;
p[i+1] = p[i] ^ val;
}
block = n / sqrt(m) + 1;
vector<Query> qry(m);
for (int i = 0; i < m; i++) {
int l = rnd() % n + 1, r = rnd() % n + 1;
if (l > r) {
swap(l, r);
}
qry[i].l = l; qry[i].r = r;
qry[i].idx = i;
}
int64_t ans = 0;
vector<int64_t> res(m);
vector<int64_t> cnt((int)2e6, 0);
sort(qry.begin(), qry.end());
int l = 0, r = 1;
ans = (p[1] == k);
cnt[p[0]]++; cnt[p[1]]++;
for (Query q: qry) {
while (l > q.l) {
l--;
ans += cnt[p[l] ^ k];
cnt[p[l]]++;
}
while (r < q.r) {
r++;
ans += cnt[p[r] ^ k];
cnt[p[r]]++;
}
while (l < q.l) {
cnt[p[l]]--;
ans -= cnt[p[l] ^ k];
l++;
}
while (r > q.r) {
cnt[p[r]]--;
ans -= cnt[p[r] ^ k];
r--;
}
res[q.idx] = ans;
}
uint64_t rhsh = 0;
for (int i = 0; i < m; i++) {
rhsh *= (uint64_t)1e9 + 7;
rhsh += (uint64_t)res[i];
}
cout << rhsh << "\n";
return 0;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGJpdHNldD4KI2luY2x1ZGUgPGNhc3NlcnQ+CiNpbmNsdWRlIDxjbGltaXRzPgojaW5jbHVkZSA8Y3N0ZGludD4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8cmFuZG9tPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxzc3RyZWFtPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx2ZWN0b3I+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2lmZGVmIERFQlVHCgkvLyNkZWZpbmUgTE9DQUxfSU5QVVRfRklMRQojZWxzZQoJLy8jZGVmaW5lIFVTRV9GSUxFX0lPCiNlbmRpZgoKI2lmZGVmIFVTRV9GSUxFX0lPCgkjZGVmaW5lIElOUFVUX0ZJTEUgImlucHV0LnR4dCIKCSNk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