#include <bits/stdc++.h>
long Bigmod(long b, long p, long m) {
  if (p == 0)
    return 1;
  else if (p % 2 == 0)
    return (Bigmod(b, p / 2, m) * Bigmod(b, p / 2, m)) % m;
  else
    return ((b % m) * Bigmod(b, p - 1, m)) % m;
}
int main() {
  long n, i, j, k, ans = 0, p;
  scanf("%ld", &p);
  for (i = 1; i < p; i++) {
    n = Bigmod(i, p - 1, p);
    n = (n - 1 + p) % p;
    if (!n) {
      for (j = 1; j <= p - 2; j++) {
        k = Bigmod(i, j, p);
        k = (k - 1 + p) % p;
        if (!k) break;
      }
      ans += (j > (p - 2));
    }
  }
  printf("%ld\n", ans);
  return 0;
}
