//递推公式:f[1] = 0 ,f[n] = (f[n - 1] + K) mod n //如果想了解:http://blog.csdn.net/taoyanqi8932/article/details/52335719
#include <stdio.h>
int lastNum(int n)
{
int res=0;
for (int i=2;i<=n;i++)
res=(res+3)%i;
return res;
}
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
int m;
m=lastNum(n);
printf("%d\n",m);
}
return 0;
}