#include <bits/stdc++.h>
using namespace std;
int seed, n;
int rnd() { return seed = (seed * 19260817ll + 20230853) & INT_MAX; }
const int N = 5e7 + 9, M = 1 << 26;
int a[N], zkw[1 << 27];
int bpos[N];
int tot, mx;
inline void push(int x) {
a[++tot] = x;
zkw[M + tot] = tot;
for (int pos = M + tot; pos & 1; pos >>= 1)
zkw[pos >> 1] = a[zkw[pos]] < a[zkw[pos ^ 1]] ? zkw[pos] : zkw[pos ^ 1];
if (a[mx] > x) mx = tot;
}
inline int top() { return a[mx]; }
inline void pop() {
a[mx] = INT_MAX;
for (int pos = M + mx; zkw[pos >> 1]; pos >>= 1)
zkw[pos >> 1] = a[zkw[pos]] < a[zkw[pos ^ 1]] ? zkw[pos] : zkw[pos ^ 1];
for (int x = tot + 1; x; x &= x - 1) {
int tmpmx = zkw[bpos[x]];
if (a[mx] > a[tmpmx]) mx = tmpmx;
}
}
int main() {
cin >> n >> seed;
int ans = 0;
a[0] = INT_MAX;
for (int i = 1; i <= n; ++i) {
int w = i + M;
while (w & 1) w >>= 1;
bpos[i + 1] = w;
}
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;
}