#include <bits/stdc++.h> using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int eular_phi(int n) { vector<int> primes; int x = n; for (int i = 2; i * i <= n; i++) { if (x % i == 0) { primes.push_back(i); while (x % i == 0) { x /= i; } } } if (x > 1) { primes.push_back(x); } int res = n; for (int p : primes) { res /= p; res *= (p - 1); } return res; } int pow_mod(long long a, int n, int mod) { long long res = 1; while (n) { if (n & 1) { res = (res * a) % mod; } a = (a * a) % mod; n >>= 1; } return res; } int main() { fast_io(); int n; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } int phi = eular_phi(n); vector<int> divisors; for (int i = 1; i * i <= phi; i++) { if (phi % i == 0) { divisors.push_back(i); if (i * i != phi) { divisors.push_back(phi / i); } } } sort(divisors.begin(), divisors.end()); for (int d : divisors) { if (pow_mod(10, d, n) == 1) { cout << d << endl; return 0; } } }