#include <bits/stdc++.h>
using namespace std;
int P;
bool chack(int n) {
  int i, Mod = n;
  for (i = 1; i < P - 2; i++) {
    Mod = (n * Mod) % P;
    if (Mod == 1) return 0;
  }
  Mod = (n * Mod) % P;
  if (Mod == 1) return 1;
  return 0;
}
int main(void) {
  int i, j = 0;
  cin >> P;
  if (P == 2) j = 1;
  for (i = 2; i < P; i++)
    if (chack(i)) {
      j++;
    }
  cout << j << "\n";
}
