Example

Input

3


Output

1
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int pow_mod(int a, int n, int m = MOD) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

int inv_mod(int a, int m = MOD) {
  int b = m, x = 1, y = 0;
  while (b) {
    int t = a/b;
    a -= t*b; swap(a,b);
    x -= t*y; swap(x,y);
  }
  x %= m;
  if (x < 0) x += m;
  return x;
}

int log_mod(int a, int b, int m = MOD) {
  a %= m; b %= m;
  int ok = m, ng = -1;
  while (ok - ng > 1) {
    int mid = (ok + ng) / 2;
    if (mid * mid >= m) ok = mid;
    else ng = mid;
  }
  unordered_map<int,int> baby;
  baby.reserve(ok);
  int factor = 1;
  for (int i = 0, e = b; i < ok; i++) {
    baby[e] = i;
    (factor *= a) %= m;
    (e *= a) %= m;
  }
  for (int i = 1, e = factor; i <= ok; i++) {
    auto it = baby.find(e);
    if (it != end(baby)) return i * ok - it->second;
    (e *= factor) %= m;
  }
  return -1;
}

map<int,int> prime_factor(int x) {
  map<int,int> res;
  for (int i = 2; i*i <= x; i++) {
    while (x % i == 0) {
      res[i]++;
      x /= i;
    }
  }
  if (x != 1) res[x]++;
  return res;
}

int gcd(int a, int b) {
  while (b) {
    int c = a % b;
    a = b; b = c;
  }
  return a;
}

int lcm(int a, int b) {
  return a / gcd(a,b) * b;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  auto pf = prime_factor(N);
  int LCM = 1;
  for (auto p : pf) {
    if (p.second != 1) {
      cout << -1 << endl;
      return 0;
    }
    LCM = lcm(LCM,p.first-1);
  }
  cout << (gcd(N,LCM) != 1 ? -1 : log_mod(N,1,LCM)) << endl;

  return 0;
}
