#include <bits/stdc++.h>
using namespace std;
int idx1 = -1, idx2 = -1, c, ans;
string s1, s2;
int main() {
  cin >> c;
  for (int i = 1; i < c; i++) {
    int cur = i;
    bool f = true;
    for (int j = 1; j <= c - 2; j++) {
      if ((cur - 1) % c == 0) f = false;
      if (j != c - 2) cur = (cur * i) % c;
    }
    cur *= i;
    if (f && (cur - 1) % c == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
