#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int p;
  cin >> p;
  long long int ans = 0;
  for (long long int i = 1; i < p; i++) {
    long long int t = 1;
    int flg = 0;
    for (long long int j = 1; j < p - 1; j++) {
      t = (t * i) % p;
      if (t == 1) {
        flg = 1;
        break;
      }
    }
    if (flg == 0) {
      t = (t * i) % p;
      if (t == 1) ans++;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
