#include <bits/stdc++.h>
using namespace std;
void solve() {
  int p;
  cin >> p;
  int count = 0, k = 0;
  for (int x = 1; x < p; x++) {
    k = 1;
    for (int i = 1; i < p - 1; i++) {
      k = (x * k) % p;
      if (k == 1) {
        goto abc;
      }
    }
    if (k * x % p == 1) {
      count++;
    }
  abc:;
  }
  cout << count;
  return;
}
int main() { solve(); }
