#C, trial division, 75 bytes#
i=1; main(n){for(scanf("%d",&n);n%i++&&i<n;);printf("%d",n<3?n-1:n%i);} Note special handling for n=1,2
Also, here's the version that takes n at the commandline, at 81 bytes.
i=1; main(int n,char**v){for(n=atoi(v[1]);n%i++&&i<n;);printf("%d",n<3?n-1:n%i);}