#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int main() {
  int p;
  cin >> p;
  int cnt = 0;
  for (int i = 1; i < p; ++i) {
    bool good = true;
    int x = 1;
    for (int j = 1; j < p - 1; ++j) {
      x *= i;
      x %= p;
      if (x == 1) good = false;
    }
    x *= i;
    x %= p;
    if (x != 1) good = false;
    cnt += (good == true);
  }
  cout << cnt << endl;
  return 0;
}
