#include <bits/stdc++.h>
using namespace std;
long long p;
bool u[2010];
bool f(long long n) {
  long long s = n;
  long long ch = 1;
  while (!u[s] && s != 1) {
    u[s] = 1;
    s *= n;
    s %= p;
    ch++;
  }
  return (ch == p - 1 && s == 1);
}
int main() {
  cin >> p;
  if (p == 2) {
    cout << 1;
    return 0;
  }
  long long ch = 0;
  for (long long i = 2; i < p; i++) {
    memset(u, 0, sizeof(u));
    if (f(i)) ch++;
  }
  cout << ch;
  return 0;
}
