#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p, x, root = 0, y = 0;
  cin >> p;
  for (long long i = 1; i < p; i++) {
    x = 1;
    y = 0;
    for (long long j = 1; j <= p - 2; j++) {
      x = (x * i) % p;
      if ((x - 1) % p == 0) {
        break;
      } else
        y++;
    }
    if ((x * i - 1) % p == 0 && y == p - 2) {
      root++;
    }
  }
  cout << root;
  return 0;
}
