#include <bits/stdc++.h>
using namespace std;
int x[2005][2005];
int main() {
  int x, p;
  while (cin >> p) {
    int p2, p1, res = 0;
    for (int i = 1; i < p; i++) {
      p2 = i;
      bool flag = true;
      for (int j = 1; j <= p - 2; j++) {
        if ((p2 - 1) % p == 0) {
          flag = false;
          break;
        }
        p2 *= i;
        p2 %= p;
      }
      p2 %= p;
      if (flag && (p2 - 1) % p == 0) res++;
    }
    cout << res << endl;
  }
  return 0;
}
