#include <bits/stdc++.h>
int MOD;
int pow(int a, int b) {
  int x = 1, y = a;
  while (b > 0LL) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > MOD) x %= MOD;
    }
    y = (y * y);
    if (y > MOD) y %= MOD;
    b /= 2;
  }
  return x;
}
int main() {
  int k, count = 0, i, j;
  scanf("%d", &MOD);
  for (i = 1; i < MOD; ++i) {
    k = 1;
    for (j = 1; j < MOD - 1; ++j) {
      if (pow(i, j) == 1) {
        k = 0;
        break;
      }
    }
    if (k && pow(i, MOD - 1) == 1) ++count;
  }
  printf("%d", count);
  return 0;
}
