// #ifdef LOCAL
// #define _GLIBCXX_DEBUG
// #endif
#include <bits/stdc++.h>
using namespace std;

#pragma region aliases

#define rep(i, n) for(long long i = 0; i < (n); i++)
#define rrep(i, n) for(long long i = (n)-1; i > -1; i--)
#define Rep(i, m, n) for(long long i = (m); i < (n); i++)
#define rRep(i, m, n) for(long long i = (n)-1; i >= (m); i--)
#define REP(i, m, n, p) for(long long i = m; i < n; i += p)
#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bcnt(n) __builtin_popcountll(n)
#define endk endl
#define ednl endl
#define enld endl

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using qll = queue<long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
template <class T = ll>
using V = vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
//昇順pq(小さい方から取り出す)
template <class T = ll>
using pqup = priority_queue<T, vector<T>, greater<T>>;
//降順pq(大きい方から取り出す)
template <class T = ll>
using pqdn = priority_queue<T>;

#pragma endregion

#pragma region constants

long long const limLL = 9223372036854775807;  // POW(2,63)-1 ~ 9.22e18
long long const dekai = 3e16;
const long double pi = acos(-1);
const char dl = '\n';
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

const int mod = 1000000007;
// const int mod = 998244353;

#pragma endregion

#pragma region basic_procedure

template <class T>
inline bool isin(T x, T lef, T rig) {
	return ((lef <= x) && (x < rig));
}

template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}

void Yes(bool f = 1) { cout << (f ? "Yes" : "No") << "\n"; }
void No() { cout << "No\n"; }
void YES(bool f = 1) { cout << (f ? "YES" : "NO") << "\n"; }
void NO() { cout << "NO\n"; }
template <class T>
void drop(T answer) {
	cout << answer << "\n";
	exit(0);
}
void err() {
	cout << -1 << "\n";
	exit(0);
}

template <class T>
void vout(vector<T> &v, bool tate = 0) {
	if(v.size() > 0) {
		for(auto it = v.begin(); it < v.end(); it++) {
			cout << *it;
			if(it != v.end() - 1) {
				if(tate)
					cout << endl;
				else
					cout << " ";
			}
		}
	}
	cout << endl;
}

template <class T>
void add(vector<T> &v, T val) {	 //ベクトルの各要素に加算
	for(auto &a : v) a += val;
	return;
}

// vectorの中身を数える map<要素,個数>を返す
template <class T>
map<T, long long> cntv(vector<T> v) {
	map<T, long long> m;
	for(auto &g : v) {
		if(m.count(g))
			m[g]++;
		else
			m[g] = 1;
	}
	return m;
}

//配列圧縮
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1,  0}にする
template <class T>
vector<long long> press(vector<T> &v) {
	long long n = v.size();
	vector<long long> w(n);
	map<T, long long> m;
	for(T &p : v) m[p] = 0;
	long long i = 0;
	for(auto &p : m) {
		p.second = i;
		i++;
	}
	for(long long i = 0; i < n; i++) w.at(i) = m[v.at(i)];
	return w;
}

// 切り上げ除算
template <class T>
T dup(T a, T b) {
	assert(b != 0);
	T x = abs(a);
	T y = abs(b);
	T z = (x + y - 1) / y;
	if((a < 0 && b > 0) || (a > 0 && b < 0))
		return -z;
	else if(a == 0)
		return 0;
	else
		return z;
}

long long POW(long long a, long long n) {
	long long res = 1;
	while(n > 0) {
		if(n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	if(mod == 1) return 0LL;
	long long res = 1;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// a * x % mod == __gcd(a,mod)なるxを返す
// a が modの倍数でないことが条件
long long modinv(long long a, long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

vvll comb(100, vll(100, -1));
long long com(long long n, long long k) {  //普通の二項計数(overflowに注意)
	assert(n < 100 && k < 100);
	if(n < k || k < 0 || n < 0) return 0;
	if(comb[n][k] != -1) return comb[n][k];
	ll res;
	if(n - k < k)
		res = com(n, n - k);
	else if(k == 0)
		res = 1;
	else
		res = com(n - 1, k - 1) + com(n - 1, k);
	comb[n][k] = res;
	return res;
}

// nCk modを求める
const int MAX = 5100000;
// この値は求める二項計数の値に応じて変える
// MAX=3*10^7のとき1900msほど、ほぼ比例
// MAX=5*10^6程度ならそれほど気にしなくてよい(300ms程)
long long fac[MAX], finv[MAX], inv[MAX];

void cominit() {
	// テーブルを作る前処理
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long commod(long long n, long long k) {  // 二項係数
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long pmod(long long n, long long k) {	// 順列
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * finv[n - k] % mod;
}
// n個の区別しないボールを区別するk個の箱に入れる方法の総数
long long hmod(long long n, long long k) {	// 重複組み合わせ
	return commod(n + k - 1, n);
}
#pragma endregion

#pragma region input
#define VEC(type, name, size) \
	vector<type> name(size);  \
	INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	INPUT(__VA_ARGS__)

template <class T>
void scan(T &a) {
	cin >> a;
}
template <class T>
void scan(vector<T> &a) {
	for(auto &i : a) scan(i);
}
template <class T, class L>
void scan(pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
template <class T>
inline void print(T x) {
	cout << x << '\n';
}

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}
#pragma endregion

#pragma region debug

#pragma region output
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
	for(int i = 0; i < (int)v.size(); i++) {
		if(i) os << " ";
		os << v[i];
	}
	return os;
}
#pragma endregion

#pragma region view

template <typename T>
void view(const T e) {
	std::cerr << e;
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << "(";
	view(p.first);
	cerr << ", ";
	view(p.second);
	cerr << ")";
}

template <typename T>
void view(std::set<T> &s) {
	if(s.empty()) {
		cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(auto &t : s) {
		view(t);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::vector<T> &v) {
	if(v.empty()) {
		cerr << "{ }";
		return;
	}
	std::cerr << "{ ";
	for(const auto &e : v) {
		view(e);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	std::cerr << "{\n";
	for(const auto &v : vv) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	std::cerr << "{\n";
	for(const auto &c : v) {
		std::cerr << "\t(";
		view(c.first);
		cerr << ", ";
		view(c.second);
		cerr << ")\n";
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(auto &t : m) {
		std::cerr << "\t[";
		view(t.first);
		cerr << "] : ";
		view(t.second);
		cerr << "\n";
	}
	std::cerr << "}";
}

#pragma endregion

// when debugging : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	view(H);
	cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                           \
	do {                                                     \
		cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                              \
		cerr << "\b\b]\n";                                   \
	} while(0)
#define dump(x)                                 \
	do {                                        \
		cerr << __LINE__ << " " << #x << " : "; \
		view(x);                                \
		cerr << "\n";                           \
	} while(0)

#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

#pragma endregion

#pragma region FFT

using Real = double;  // long doubleにすると3倍くらいに重くなる？
const Real PI = acos(-1);
// Cooley–Tukey FFT algorithm O(N log N)
// 要素数を2冪にしてから突っ込みましょう
vector<complex<Real>> fft(vector<complex<Real>> a, bool inverse = false) {
	int n = a.size();
	int h = 0;	// h = log_2(n)
	for(int i = 0; 1 << i < n; i++) h++;
	// バタフライ演算用の配置入れ替え
	for(int i = 0; i < n; i++) {
		int j = 0;
		for(int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
		if(i < j) swap(a[i], a[j]);
	}
	// バタフライ演算
	for(int b = 1; b < n; b *= 2) {
		// 第 log_2(b) + 1 段
		// ブロックサイズ = b * 2
		for(int j = 0; j < b; j++) {
			// ブロック内 j 個目
			// 重み w = (1 の原始 2b 乗根の j 乗)
			complex<Real> w = polar((Real)1.0, (2 * PI) / (2 * b) * j * (inverse ? 1 : -1));
			for(int k = 0; k < n; k += b * 2) {
				// k を先頭とするブロック
				complex<Real> s = a[j + k];			 // 前
				complex<Real> t = a[j + k + b] * w;	 // 後
				a[j + k] = s + t;					 // 前の更新
				a[j + k + b] = s - t;				 // 後の更新
			}
		}
	}
	// 逆変換時にサイズで割る調整
	if(inverse)
		for(int i = 0; i < n; i++) a[i] /= n;
	return a;
}
// Cooley–Tukey FFT algorithm O(N log N)
vector<complex<Real>> fft(vector<Real> a, bool inverse = false) {
	vector<complex<Real>> a_complex(a.size());
	for(int i = 0; i < a.size(); i++) a_complex[i] = complex<Real>(a[i], 0);
	return fft(a_complex, inverse);
}

// FFT による畳み込み O(N log N)
vector<Real> convolve(vector<Real> a, vector<Real> b) {
	int s = a.size() + b.size() - 1;  // 畳み込み結果のサイズ
	int t = 1;						  // FFT に使う配列のサイズ（2 の累乗）
	while(t < s) t *= 2;
	a.resize(t);  // FFT するためにリサイズ
	b.resize(t);  // FFT するためにリサイズ
	vector<complex<Real>> A = fft(a);
	vector<complex<Real>> B = fft(b);
	for(int i = 0; i < t; i++) {
		A[i] *= B[i];  // 畳み込み結果の FFT 結果を得る
	}
	A = fft(A, true);								// IFFT で畳み込み結果を得る
	a.resize(s);									// 畳み込み結果を入れるためにリサイズ
	for(int i = 0; i < s; i++) a[i] = A[i].real();	// 実部が答え
	return a;
}

template <typename T>
vector<T> convolve(vector<T> &a, vector<T> &b) {
	vector<Real> c, d;
	for(auto &t : a) {
		c.push_back((Real)t);
	}
	for(auto &t : b) {
		d.push_back((Real)t);
	}
	vector<Real> res = convolve(c, d);
	vector<T> e;
	for(auto &t : res) {
		e.push_back((T)(0.5 + t));
	}
	return e;
}

#pragma endregion

#pragma region NTT

const int MOD = 998244353;
const int root = 3;

unsigned int add(const unsigned int x, const unsigned int y) { return (x + y < MOD) ? x + y : x + y - MOD; }

unsigned int sub(const unsigned int x, const unsigned int y) { return (x >= y) ? (x - y) : (MOD - y + x); }

unsigned int mul(const unsigned int x, const unsigned int y) { return (unsigned long long)x * y % MOD; }

unsigned int mod_pow(unsigned int x, unsigned int n) {
	unsigned int res = 1;
	while(n > 0) {
		if(n & 1) {
			res = mul(res, x);
		}
		x = mul(x, x);
		n >>= 1;
	}
	return res;
}

unsigned int inverse(const unsigned int x) { return mod_pow(x, MOD - 2); }

void ntt(vector<int> &a, const bool rev = false) {
	unsigned int i, j, k, l, p, q, r, s;
	const unsigned int size = a.size();
	if(size == 1) return;
	vector<int> b(size);
	r = rev ? (MOD - 1 - (MOD - 1) / size) : (MOD - 1) / size;
	s = mod_pow(root, r);
	vector<unsigned int> kp(size / 2 + 1, 1);
	for(i = 0; i < size / 2; ++i) kp[i + 1] = mul(kp[i], s);
	for(i = 1, l = size / 2; i < size; i <<= 1, l >>= 1) {
		for(j = 0, r = 0; j < l; ++j, r += i) {
			for(k = 0, s = kp[i * j]; k < i; ++k) {
				p = a[k + r], q = a[k + r + size / 2];
				b[k + 2 * r] = add(p, q);
				b[k + 2 * r + i] = mul(sub(p, q), s);
			}
		}
		swap(a, b);
	}
	if(rev) {
		s = inverse(size);
		for(i = 0; i < size; i++) {
			a[i] = mul(a[i], s);
		}
	}
}

vector<int> convolute(const vector<int> &a, const vector<int> &b) {
	const int size = (int)a.size() + (int)b.size() - 1;
	int t = 1;
	while(t < size) {
		t <<= 1;
	}
	vector<int> A(t, 0), B(t, 0);
	for(int i = 0; i < (int)a.size(); i++) {
		A[i] = a[i];
	}
	for(int i = 0; i < (int)b.size(); i++) {
		B[i] = b[i];
	}
	ntt(A), ntt(B);
	for(int i = 0; i < t; i++) {
		A[i] = mul(A[i], B[i]);
	}
	ntt(A, true);
	A.resize(size);
	return A;
}

#pragma endregion

ll dek = POW(10, 15);

int main() {
	ll plus = 0;

	ll k;
	cin >> k;
	while(k % 5 == 0) k /= 5;
	while(k % 2 == 0) k /= 2;
	if(k == 1) drop(1);

	sll s;
	ll n = 1;
	while(1) {
		if(s.count(n)) break;
		s.insert(n);
		n *= 10;
		n %= k;
	}
	vi v(k);
	for(auto g : s) v[g] = 1;

	int ans = 1;
	auto now = v;
	while(1) {
		auto w = convolute(now, v);
		ans++;
		w.push_back(0);
		rep(i, k) { now[i] = (w[i] + w[i + k]) > 0; }
		if(now[0]) {
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 10660