main(n){scanf("%d",&n);return !printf("%d\n",n%123456);}