#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, p, ans = 0;
  cin >> p;
  for (i = 1; i < p; ++i) {
    int temp = i;
    for (j = 1; j < p; ++j) {
      if ((temp - 1) % p == 0) break;
      temp = temp * i % p;
    }
    if (j == p - 1) ++ans;
  }
  printf("%d\n", ans);
}
