Problem:
Score : 300 points

Problem Statement

Takahashi loves the number 7 and multiples of K.

Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.)

If the sequence contains no multiples of K, print -1 instead.

Constraints

1 \leq K \leq 10^6

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)

Sample Input 1

101

Sample Output 1

4

None of 7, 77, and 777 is a multiple of 101, but 7777 is.

Sample Input 2

2

Sample Output 2

-1

All elements in the sequence are odd numbers; there are no multiples of 2.

Sample Input 3

999983

Sample Output 3

999982

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

                         /*  (: ///////|||||| BEGINS |||||||\\\\ :) */
/* REMEMBER
Deletes all characters except first one     Deletes 4 characters from index number 1
    str.erase(1);                               str.erase(1,4);
Deletes character at position 4
 str.erase(str.begin() + 4);
bool compare(const pair<int, int>&a, const pair<int, int>&b)
{
   return a.second<b.second;
}
maxn = max_element(mp.begin(), mp.end(), compare)->second;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}
priority_queue <int, vector<int>, greater<int>> gquiz; // to create min heap
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
const int inf=0x3f3f3f3f;
#define mod  1000000007
#define fo(i,n) for(int i=1;i<=n;i++)
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define three_max(n1,n2,n3) (n1 > n2)?(n1>n3?n1:n3):(n2>n3?n2:n3)
#define lb lower_bound
#define ub upper_bound
#define tr(it, a) for(auto it = a.begin();it!=a.end();it++)
#define gcd(a,b) __gcd(a,b)
#define pq priority_queue 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
long long isprime(long long n)
{
    for(long long i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)return 0;
    }
    return 1;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

vector<ll>v;
v.pb(7);
v.pb(77);
v.pb(777);
v.pb(7777);
v.pb(77777);
v.pb(777777);
v.pb(7777777);
ll k;
cin>>k;
for(ll i=0;i<v.size();i++)
{
if(v[i]%k==0)
{
    cout<<i+1<<endl;
    return 0;
}
}
cout<<-1<<endl;
return 0;
}