#include <bits/stdc++.h>
using namespace std;
int a[2013];
int main() {
  int p, flag, tp;
  cin >> p;
  int ans = 0;
  for (int i = 1; i < p; i++) {
    int x = 1;
    for (int j = 1; j < p; j++) {
      a[j] = (x * i) % p;
      x = (x * i) % p;
    }
    flag = 1;
    for (int j = 1; j < p; j++) {
      if (j < p - 1) {
        if (a[j] == 1) {
          flag = 0;
          break;
        }
      }
      if (a[p - 1] != 1) {
        flag = 0;
        break;
      }
    }
    if (flag) ans++;
  }
  cout << ans << endl;
  return 0;
}
