#include <bits/stdc++.h>
int cal(int max) {
  int i, sum = 0, j, k, da;
  for (k = 1; k < max; k++) {
    da = k;
    int flag = 1;
    for (j = 1; j < max - 1; j++) {
      if ((da - 1) % max == 0) {
        flag = 0;
        break;
      } else
        da = da * k % max;
    }
    if ((flag == 1) && ((da - 1) % max == 0)) sum++;
  }
  return sum;
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    printf("%d\n", cal(n));
  }
  return 0;
}
