#include <bits/stdc++.h>
using namespace std;
int seed, n;
int rnd() { return seed = (seed * 19260817ll + 20230853) & INT_MAX; }
const int N = 1e8 + 9;
int hp[N];
int tot;
inline void push(int x) {
hp[++tot] = x;
for (int w = tot; hp[w] < hp[w >> 1]; w >>= 1) swap(hp[w], hp[w >> 1]);
}
inline void pop() {
swap(hp[1], hp[tot--]);
int pos = 1;
while (1) {
if ((pos << 1) > tot) break;
int* a = hp + (pos << 1);
if ((pos << 1 | 1) <= tot && *a > *(a + 1)) ++a;
if (hp[pos] < *a) break;
swap(hp[pos], *a);
pos = a - hp;
}
}
inline int top() { return hp[1]; }
int main() {
cin >> n >> seed;
int ans = 0;
for (int i = 1; i <= (n >> 1); ++i) push(rnd());
for (int i = 1; i <= (n >> 1); ++i) {
switch (rnd() % 3) {
case 0:
push(rnd());
break;
case 1:
pop();
break;
default:
ans ^= top();
}
}
cout << ans << endl;
return 0;
}