//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int X = 1e6+10;
struct Sieve {
	int n;
	vector<int> f, primes;
	Sieve(int n=1):n(n), f(n+1) {
		f[0] = f[1] = -1;
		for(int64_t i=2; i<=n; ++i) {
			if(f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for(int64_t j = i*i; j <= n; j += i) {
				if(!f[j]) f[j] = i;
			}
		}
	}
	//素数判定
	bool isPrime(int x) {return f[x] == x;}
	//素数判定(1つ用)(宣言はsqrt(x)のサイズで)
	bool isPrime1(int64_t x) {
		bool m = true;
		for(int z:primes) {
			if(!(x%z)) {
				m = false;
				break;
			}
		}
		return m;
	}
	//素数列挙
	vector<int > factorList(int x) {
		assert(x <= n);
		vector<int> res;
		while(x != 1) {
			res.emplace_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	//素因数分解　pair(素数, 素因数の数)
	vector<pair<int, int> > factor(int x) {
		vector<int> fl = factorList(x);
		if(fl.size() == 0) return {};
		vector<pair<int, int> > res(1, pair<int, int>(fl[0], 0));
		for(int p : fl) {
			if(res.back().first == p) {
				++res.back().second;
			} else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
	//素数列挙(1つ用)(宣言はsqrt(x)のサイズで)
	vector<int64_t> factorList1(int64_t x) {
		vector<int64_t> vec;
		for(int z:primes) {
			while(!(x%z)) {
				vec.emplace_back(z);
				x /= z;
			}
		}
		if(x != 1) vec.emplace_back(x);
		return vec;
	}
	//素数列挙(1つ用)(宣言はsqrt(x)のサイズで)　pair(素数, 素因数の数)
	vector<pair<int64_t, int> > factor1(int64_t x) {
		vector<int64_t> vec = factorList1(x);
		vector<pair<int64_t, int> > vecc;
		for(vector<int64_t>::iterator itr = vec.begin(); itr != vec.end(); ++itr) {
			if(itr != vec.begin() && *itr == *(itr-1)) {
				(vecc.end()-1)->second++;
			} else {
				vecc.emplace_back(pair<int64_t, int>(*itr, 1));
			}
		}
		return vecc;
	}
	//約数列挙
	vector<int64_t> div1(int64_t x) {
		vector<int64_t> res(1, 1);
		vector<pair<int64_t, int> > fac = factor1(x);
		for(int i = 0; i < fac.size(); ++i) {
			int si = res.size();
			for(int j = 0; j < fac[i].second; ++j) {
				for(int k = 0; k < si; ++k) {
					res.emplace_back(res[k+j*si]*fac[i].first);
				}
			}
		}
		sort(res.begin(), res.end());
		return res;
	}
};

//head

ll k, m, hg, x, lll;
pair<ll, int> res[X];

ll pow(ll x, ll p) {
	if(!p) return 1LL;
	__int128_t wo = pow(x, p>>1);
	wo *= wo;
	wo %= k;
	if(p&1) wo *= x;
	ll res = wo%k;
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> k;
	if(~k&1 or k%5 == 0) {
		cout << -1 << endl;
		return 0;
	}
	m = sqrt(k)+1;
	res[0].first = 7%k;
	x = 1;
	rep(i, m) {
		ll nb = res[i].first;
		nb *= 10;
		nb += 7;
		res[i+1] = make_pair(nb%k, i+1);
		x *= 10;
		x %= k;
	}
	hg = res[m-1].first;
	sort(res, res+m+1);
	if(res[0].first == 0) {
		cout << res[0].second+1 << endl;
		return 0;
	}

	Sieve pri(sqrt(k));
	auto y = pri.factor1(k);
	lll = k;
	rep(i, y.size()) {
		lll /= y[i].first;
		lll *= y[i].first-1;
	}
	x = pow(x, lll-1);

	ll now = 0;
	rep(i, m) {
		now -= hg;
		now += k;
		now %= k;
		__int128_t wo = now;
		wo *= x;
		now = wo%k;

		//cout << now << ' ' << i+1 << endl;
		pair<ll, int> *b = lower_bound(res, res+m+1, make_pair(now, 0));
		if(b->first == now) {
			cout << b->second + (i+1)*m + 1 << endl;
			return 0;
		}
	}

	cout << -1 << endl;
}

Measured memory_bytes: 3692