#include<bits/stdc++.h> using namespace std; int main(){ int n,s,xi[200]={0},yi[200]={0},ans=0; cin>>n>>s; for(int i=1;i<n;i++) s=(s*345)%19997,xi[97+s%26]++; for(int i=1;i<n;i++) s=(s*345)%19997,yi[97+s%26]++; for(int i=0;i<=199) ans+=abs(xi[i]-yi[i]); cout<<ans<<endl; return 0; }