#include <bits/stdc++.h>
using namespace std;
bool ok(int x, int p) {
  bool good = true;
  int cur = 1;
  for (int i = 1; i < (p - 1); i++) {
    cur *= x;
    cur %= p;
    int curnum = ((cur - 1) + p) % p;
    if (curnum == 0) return false;
  }
  cur *= x;
  cur %= p;
  cur = ((cur - 1) + p) % p;
  if (cur == 0) return true;
  return false;
}
int solve(int p) {
  int ret = 0;
  for (int i = 1; i < p; i++) {
    if (ok(i, p)) ret++;
  }
  return ret;
}
int main() {
  int p = 0;
  cin >> p;
  int res = solve(p);
  cout << res << endl;
  return 0;
}
