#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long p;
  cin >> p;
  long long ans = 0;
  for (long long x = 1; x <= p; ++x) {
    long long t = x;
    long long j = 1;
    bool f = 1;
    while (j <= p - 2) {
      if (t % p == 1) f = 0;
      j++;
      t = (t * x) % p;
    }
    if ((t - 1) % p) f = 0;
    if (f) ans++;
  }
  cout << ans;
  return 0;
}
