#include<stdio.h> int n,m,t1[200],t2[200],ans; int main(){ scanf("%d %d",&n,&s); for(int i=1;i<=n;i++) s=(s*345)%19997,t1[97+s%26]++; for(int i=1;i<=n;i++) s=(s*345)%19997,t2[97+s%26]++; for(int i=1;i<=150;i++){ if(t2[i]) ans+=t2[i]-t1[i]>0?t2[i]-t1[i]:0; } printf("%d",ans); return 0; }