#include <bits/stdc++.h>
using namespace std;
void solve() {
  int p;
  cin >> p;
  int ans = 0;
  for (int i = 1; i < p; i++) {
    bool ok = 1;
    long long first = i;
    for (int j = 0; j < p - 2; j++) {
      if (first % p == 1) {
        ok = 0;
      }
      first = (first * i) % p;
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
