#include <bits/stdc++.h>
using namespace std;
int main() {
  int p;
  cin >> p;
  int ans = 0;
  for (int i = 1; i < p; i++) {
    bool flag = true;
    int cur = 1;
    for (int j = 1; j < p - 1; j++) {
      cur = cur * i % p;
      if ((cur - 1) % p == 0) {
        flag = false;
        break;
      }
    }
    cur = cur * i % p - 1;
    if (flag && cur % p == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}
