CodeEff/ECCO huggingface dataset:
# Original solution
N, M = list(map(int,input().split()))
check_lis = [-1 for _ in range(N)]
for _ in range(M):
    s,c = list(map(int,input().split()))
    if check_lis[s-1] == -1:
        check_lis[s-1] = c
    else:
        if check_lis[s-1] != c:
            print('-1')
            break
    if check_lis[0] == 0 and N != 1:
        print('-1')
        break
else:
    min_range = 10 ** (N-1)
    max_range = 10 * min_range
    if min_range == 1:
        min_range = 0
    for i in range(min_range, max_range):
        for idx, check in enumerate(check_lis):
            if check == -1:
                continue
            if (i // 10 ** (N - idx - 1)) % 10 != check:
                break
        else:
            print(i)
            break

# Optimized solution
N, M = list(map(int, input().split()))
if N == 1:
    min_range = 0
    max_range = 10
else:
    min_range = 10 ** (N-1)
    max_range = 10 ** N
digits_lis = ['not defined' for _ in range(N+1)]
for _ in range(M):
    s, c = list(map(int, input().split()))
    if digits_lis[s] == 'not defined':
        digits_lis[s] = c
    else:
        if digits_lis[s] != c:
            print('-1')
            break
    if digits_lis[1] == 0 and N != 1:
        print('-1')
        break
else:
    for i in range(min_range, max_range):
        for idx, check in enumerate(digits_lis):
            if check == 'not defined':
                continue
            if (i // 10 ** (N - idx)) % 10 != check:
                break
        else:
            print(i)
            break
# Original solution
n,m=map(int,input().split())
l=[tuple(map(int,input().split())) for i in range(m)]
l=set(l)
#[s,c]

ans=['1']+['0']*(n-1)
for s,c in l:
    #1桁の数の時は例外
    if s==1 and c==0 and n>1:
        print(-1)
        exit()
    #既に変更済みの場合
    if s==1 and ans[0]!='1':
        print(-1)
        exit()
    if s!=1 and ans[s-1]!='0':
        print(-1)
        exit()

    ans[s-1]=str(c)
if m==0 and n==1:
    print(0)
    exit()
print(*ans,sep='')


# Optimized solution
n,m=map(int,input().split())
sc=set(tuple(map(int,input().split())) for i in range(m))

S=['1']+['0']*(n-1)
for s,c in sc:
    if s==1 and c==0 and n>1:
        print(-1)
        exit()
    elif s==1 and S[0]!='1':
        print(-1)
        exit()
    elif s>1 and S[s-1]!='0':
        print(-1)
        exit()
    S[s-1]=str(c)
    #print(S)
if n==1 and m==0:S='0'
print(*S,sep='')
# Original solution
N,M = list(map(int, input().split()))
ans = 0
S = [""]*N
for _ in range(M):
  s, c = list(map(int,input().split()))
  if S[s-1] == "" or S[s-1] == c:
    S[s-1] = c
  elif S[s-1] != "" and S[s-1] != c:
    print((-1))
    exit(0)
if N != 1:
  if S[0] == "":
    S[0] = 1
  if S[0] == 0:
    print((-1))
    exit(0)
  for i in range(1,N):
    if S[i] == "":
      S[i] = 0
elif N == 1:
  if S[0] == "":
    S[0] = 0
print((''.join(map(str,S))))

# Optimized solution
N,M = list(map(int, input().split()))
ans = 0
S = [""]*N
for _ in range(M):
  s, c = list(map(int,input().split()))
  if S[s-1] == "" or S[s-1] == c:
    S[s-1] = c
  elif S[s-1] != "" and S[s-1] != c:
    print((-1))
    exit(0)
if N == 3:
  if S[0] == "":
    S[0] = 1
  if S[0] == 0:
    print((-1))
    exit(0)
  if S[1] == "":
    S[1] = 0
  if S[2] == "":
    S[2] = 0
elif N == 2:
  if S[0] == "":
    S[0] = 1
  if S[0] == 0:
    print((-1))
    exit(0)
  if S[1] == "":
    S[1] = 0
elif N == 1:
  if S[0] == "":
    S[0] = 0
print((''.join(map(str,S))))
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *SC = list(map(int, read().split()))

    ans = -1
    for i in range(1000):
        n = str(i)
        if len(n) != N:
            continue
        ok = True
        for s, c in zip(*[iter(SC)] * 2):
            s -= 1
            if s >= N or n[s] != str(c):
                ok = False
                break
        if ok:
            ans = i
            break

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *SC = list(map(int, read().split()))

    A = [-1] * N
    for s, c in zip(*[iter(SC)] * 2):
        s -= 1
        if A[s] != -1 and A[s] != c:
            print((-1))
            return
        else:
            A[s] = c

    if N > 1 and A[0] == 0:
        print((-1))
        return
    elif A[0] == -1:
        if N == 1:
            A[0] = 0
        else:
            A[0] = 1

    for i in range(1, N):
        if A[i] == -1:
            A[i] = 0

    ans = ''.join(map(str, A))

    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]
i = 10**(N-1) if N > 1 else 0
while i < 10**N:
  n = [(i//10**j)%10  for j in reversed(list(range(N)))]
  f = True
  for s, c in SC:
    if n[s-1] != c:
      f = False
  if f:
    break
  i += 1
if i >= 10**N:
  print((-1))
else:
  print(i)

# Optimized solution
N, M = list(map(int, input().split()))
num = [-1]*N
err = False
for _ in range(M):
  s, c = list(map(int, input().split()))
  if num[s-1] == -1:
    num[s-1] = c
  else:
    if num[s-1] != c:
      err = True
if err or (N > 1 and num[0] == 0):
  print((-1))
else:
  ans = 0
  i = 0
  n = 0
  while i < N:
    if num[i] < 0:
      n = 1 if i == 0 and N > 1 else 0
    else:
      n = num[i]
    ans = ans * 10 + n
    i += 1
  print(ans)
# Original solution
from collections import defaultdict
d = defaultdict(list)

N, M = map(int, input().split())
for _ in range(M):
    s, c = map(int, input().split())
    d[s].append(c)

val = [-1] * N

# とりあえず桁を確定させる
for k, v in d.items():
    if len(set(v)) > 1:
        print(-1)
        exit()
    val[k - 1] = v[0]

if N == 1:
    ans = max(0, val.pop())
    print(ans)
    exit()
if N >= 2:
    if val[0] == 0:
        print(-1)
        exit()

    if val[0] == -1:
        val[0] = 1
    for i in range(N):
        val[i] = max(0, val[i])

    print(*val, sep="")


# Optimized solution
N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(M)]

ans = 10000
L = 10 ** (N - 1)
if N == 1:
    L = 0
U = 10**N

for i in range(L, U):
    x = str(i).zfill(N)
    for s, c in sc:
        if x[s - 1] == str(c):
            continue
        break
    else:
        ans = min(ans, i)

if ans >= 10000:
    ans = -1

print(ans)
# Original solution
import collections

N,M=list(map(int,input().split()))
#if not(M==0):
s=[list(map(int,input().split())) for _ in range(M)]
flag=1
l=[[i+1,-1] for i in range(N)]
ns=""
#print(l)
"""
if M==0:
    for i in range(M):
        if i==0:
            l[i][1]=1
        else:
            l[i][1]=0
        ns="".join((ns,str(l[i][1])))
    print(ns)
"""
#else:
for i in range(M):
    #print(l)
    if l[s[i][0]-1][1]==-1:
        l[s[i][0]-1][1]=s[i][1]
    else:
        if not(l[s[i][0]-1][1]==s[i][1]):
            flag=0
if (not(N==1) and (l[0][1]==0)):
    flag=0
if flag==1:
    for i in range(N):
        if not(N==1):
            if (l[i][1]==-1):
                if i==0:
                    l[i][1]=1
                else:
                    l[i][1]=0
        else:
            if (l[i][1]==-1):
                l[i][1]=0
        ns="".join((ns,str(l[i][1])))
    print(ns)
else:
    print("-1")



# Optimized solution
N,M=list(map(int,input().split()))
rest=[[] for _ in range(N)]
r2=[]
end=0
flag=0
buf=""
ans=float("inf")
end=0
for i in range(M):
    s,c=list(map(int,input().split()))
    if len(rest[s-1])==0:
        rest[s-1].append(c)
    elif rest[s-1].count(c)==0:
        end=1
        break
#print(rest)

if N == 1:
    l=list(range(0,10**N,1))
else:
    l=list(range(10**(N-1),10**N,1))
fail=0
if end!=1:
    for i in l:
        buf=str(i)
        #print(i)
        for j in range(N):
            if len(rest[j])==1:
                if buf[j]!=str(rest[j][0]):
                    fail=1
                    break
        if fail==0:
            ans=i
            flag=1
            break
        fail=0
if (flag==1):
    print(ans)
else:
    print("-1")
# Original solution
def f(K):
    sum = 0
    for i in range(K+1):
        sum += (pow(10, i, K)*7)
        sum %= K

        if sum == 0:
            return i+1
    return -1


K = int(eval(input()))

print((f(K)))


# Optimized solution
def f(K):
    sum = 0
    p10 = 1
    for i in range(K+1):
        sum += p10*7
        p10 *= 10
        p10 %= K
        sum %= K

        if sum == 0:
            return i+1
    return -1


K = int(eval(input()))

print((f(K)))
# Original solution
def solve(string):
    k = int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    n = 7
    ans = 1
    while n % k:
        n = (10 * n + 7) % k
        ans += 1
    return str(ans)


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))


# Optimized solution
def solve(string):
    k = int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    n = 7
    for i in range(k):
        if not n % k:
            return str(i + 1)
        n = (10 * n + 7) % k


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))
# Original solution

N = int(eval(input()))

r = 7
for i in range(N):
    if r % N > 0:
        r = (10 * r + 7) % N
    else:
        print((i + 1))
        break
else:
    print((-1))


# Optimized solution

K = int(eval(input()))
cur = 7
for n in range(K):
    if cur % K != 0:
        cur = (cur * 10 + 7) % K
    else:
        print((n + 1))
        break
else:
    print((-1))
# Original solution
k=int(eval(input()))
if not k&1:
    print((-1))
    exit()
ks=str(k)
carry=0
d1=int(ks[-1])
i=1
while i<=10**8:
    flag=False
    car=int(carry)
    for j in range(0,10):
        if (d1*j+car)%10==7:
            carry=str((car+k*j)//10)
            if len(carry)==carry.count('7'):
                print((i+len(carry)))
                exit()
            flag=True
            break
    if not flag:
        print((-1))
        exit()
    i+=1

# Optimized solution
k=int(eval(input()))
mod=7
cnt=1
for i in range(k):
    if mod%k==0:
        print(cnt)
        exit()
    mod=(mod*10+7)%k
    cnt+=1
print((-1))
# Original solution
k=int(eval(input()))
n=7
ans=1
if k%2==0:
    print((-1))
    exit()
while n%k!=0:
    n=(n*10+7)%k
    ans+=1
print(ans)

# Optimized solution
k=int(eval(input()))
n=7
ans=1
if k%2==0 or k%5==0:
    print((-1))
    exit()
while n%k!=0:
    n=(n*10+7)%k
    ans+=1
print(ans)
# Original solution
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(eval(input()))
    if k % 2 == 0 or k % 5 == 0:
        print((-1))
        sys.exit()
    p = 7
    plus = 7
    amari = set()
    r = 1
    while (p % k) != 0:
        if p in amari:
            print((r, -1, p))
            sys.exit()
        else:
            amari.add(p)
            plus = (plus * 10) % k
            p += plus
            p = p % k
            r += 1
    print(r)

if __name__ == '__main__':
    main()

# Optimized solution
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(eval(input()))
    if k % 2 == 0 or k % 5 == 0:
        print((-1))
        sys.exit()
    p = 7       # '7,77,777…'のmod kをいれる変数
    plus = 7    # '70,700,7000…'のmod kをいれる変数
    r = 1       # カウント
    while (p % k) != 0: # kで割り切れるかチェック
        plus = (plus * 10) % k   # pに足すもう1桁のmod kを計算。
        p += plus                # pにもう１桁を足す
        p = p % k                # pのmod kをとる
        r += 1
    print(r)

if __name__ == '__main__':
    main()
# Original solution
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(eval(input()))
    if k % 2 == 0 or k % 5 == 0:
        print((-1))
        sys.exit()
    p = 7       # '7,77,777…'のmod kをいれる変数
    plus = 7    # '70,700,7000…'のmod kをいれる変数
    r = 1       # カウント
    while (p % k) != 0: # kで割り切れるかチェック
        plus = (plus * 10) % k   # pに足すもう1桁のmod kを計算。
        p += plus                # pにもう１桁を足す
        p = p % k                # pのmod kをとる
        r += 1
    print(r)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(eval(input()))
    if k % 2 == 0 or k % 5 == 0:
        print((-1))
        sys.exit()
    if k % 7 == 0:
        l = k * 9 // 7
    else:
        l = k * 9
    r = 1       # カウント
    p = 10 ** r
    while (p % l) != 1:
        p = (p * 10) % l
        r += 1
    print(r)

if __name__ == '__main__':
    main()
# Original solution
k = int(eval(input()))
cnt = 1
ans = 7
ans %= k
flags = [False] * k
flags[ans] = True
while ans != 0:
    ans += 7*pow(10,cnt,k)
    cnt += 1
    ans %= k
    if flags[ans]:
        cnt = -1
        break
    flags[ans] = True

print(cnt)


# Optimized solution
k = int(eval(input()))
cnt = 1
ans = 7
mul = 70 % k
ans %= k
flags = [False] * k
flags[ans] = True
while ans != 0:
    ans += mul
    cnt += 1
    ans %= k
    mul *= 10
    mul %= k
    if flags[ans]:
        cnt = -1
        break
    flags[ans] = True

print(cnt)
# Original solution
k=int(eval(input()))

if k%2==0 or k%5==0:
  print((-1))
  exit()

num=7
num%=k
ans=1

while num!=0:
  num=10*num+7
  num%=k
  ans+=1

print(ans)

# Optimized solution
k=int(eval(input()))

if k%2==0 or k%5==0:
  print((-1))
  exit()

ans=1
num=7%k

while num!=0:
  num=(10*num+7)%k
  ans+=1

print(ans)
# Original solution
K = int(eval(input()))
if K % 2 == 0:
    print((-1))
    exit()
else:
    n = 7
    n_before = 7
    count = 1
    while n % K != 0:
        n = n % K
        count += 1
        n_before = 10 * n_before % K
        n = n + n_before
print(count)


# Optimized solution
K = int(eval(input()))
if K % 2 == 0 or K % 5 ==0:
    print((-1))
    exit()
else:
    n = 7
    n_before = 7
    count = 0
    while True:
        count += 1
        n = n % K
        if n == 0:
            print(count)
            exit()
        else:
            n_before = 10 * n_before % K
            n = n + n_before
print(count)
# Original solution
def solve(k):
    a_mod = 0
    for i in range(1000000):
        a_mod += 7 * pow(10, i, k)
        a_mod %= k
        if a_mod == 0:
            return i + 1
    return -1


def main():
    k = int(eval(input()))
    res = solve(k)
    print(res)


def test():
    assert solve(101) == 4
    assert solve(2) == -1
    assert solve(999983) == 999982


if __name__ == "__main__":
    test()
    main()


# Optimized solution
def solve(k):
    a_mod = 0
    pow_10 = 7
    for i in range(1000000):
        a_mod += pow_10
        a_mod %= k
        if a_mod == 0:
            return i + 1
        pow_10 *= 10
        pow_10 %= k
    return -1


def main():
    k = int(eval(input()))
    res = solve(k)
    print(res)


def test():
    assert solve(101) == 4
    assert solve(2) == -1
    assert solve(999983) == 999982


if __name__ == "__main__":
    test()
    main()
# Original solution
k = int(eval(input()))
val = 7
if k%2 == 0:
    ans = -1
else:
    for i in range(1,10**12+1):
        if val >= k:
            sub = val % k
            if sub == 0:
                  ans = i
                  break
            else:
                  val = 10 * sub + 7
        else:
            val = 10 * val + 7
print(ans)

# Optimized solution
k = int(eval(input()))
val = 7
if k%2 == 0:
    ans = -1
elif k%5 == 0:
    ans = -1
else:
    for i in range(1,10**12+1):
        if val >= k:
            sub = val % k
            if sub == 0:
                  ans = i
                  break
            else:
                  val = 10 * sub + 7
        else:
            val = 10 * val + 7
print(ans)
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K = I()
if K % 2 == 0:
    print((-1))
    exit()
if K % 7 == 0:
    K //= 7

a = 1
i = 1
while True:
    if a % K == 0:
        print(i)
        break
    else:
        a += pow(10,i,K)
        a %= K
        i += 1


# Optimized solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K = I()
if K % 2 == 0 or K % 5 == 0:
    print((-1))
    exit()
if K % 7 == 0:
    K //= 7

A = [1]
for i in range(K+2):
    A.append((A[-1]*10) % K)

a = 1
i = 1
while True:
    if a % K == 0:
        print(i)
        break
    else:
        a += A[i]
        a %= K
        i += 1
# Original solution
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()
if K % 2 == 0 or K % 5 == 0:
    print((-1))
    exit()
if K % 7 == 0:
    K //= 7

A = [1]  # A[i] = 10**i mod K
for i in range(K):
    A.append((A[-1]*10) % K)

s = 1
for i in range(1,K+1):
    if s % K == 0:
        print(i)
        exit()
    else:
        s += A[i]
        s %= K


# Optimized solution
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()
if K % 2 == 0 or K % 5 == 0:
    print((-1))
    exit()
if K % 7 == 0:
    K //= 7

s = 1
for i in range(1,K+1):
    if s % K == 0:
        print(i)
        exit()
    else:
        s *= 10
        s += 1
        s %= K
# Original solution
K = int(eval(input()))

if K % 2 == 0 or K % 5 == 0:
    print((-1))
    exit()

i = 0
ai = 0
while True:
    ai = (ai * 10 + 7) % K
    i += 1
    if ai == 0:
        break
print(i)

# Optimized solution
N = int(eval(input()))

# if N < 7:
#     print(-1)
#     exit()
if N % 2 == 0 or N % 5 == 0:
    print((-1))
    exit()
i = 0
num = 0
while True:
    num = (num * 10 + 7) % N
    i += 1
    if num == 0:
        print(i)
        exit()

K = int(eval(input()))

if K % 2 == 0 or K % 5 == 0:
    print((-1))
    exit()

i = 0
ai = 0
while True:
    ai = (ai * 10 + 7) % K
    i += 1
    if ai == 0:
        break
print(i)
# Original solution
k=int(input())
if (k%2)*(k%5)<1: exit(print(-1))
a,t,m=1,7,7
while m%k:
  a+=1
  t=t*10%k
  m+=t
print(a)


# Optimized solution
k=int(input())
t=7
for i in range(k):
  if t%k<1: exit(print(i+1))
  t=(t*10+7)%k
print(-1)
# Original solution
K = int(eval(input()))
num = 0
if K%2 == 0:
    print((-1))
else:
    for i in range(1, 100000000):
        num = num*10 + 7
        num %= K
        if num == 0:
            print(i)
            break

# Optimized solution
K = int(eval(input()))
num = 0
if K%2 == 0:
    print((-1))
else:
    for i in range(1, 1000000):
        num = num*10 + 7
        num %= K
        if num == 0:
            print(i)
            break
    else:
        print((-1))
# Original solution
k = int(eval(input()))

m = 0

for i in range(1, 10**7):
    n = m *10 +7
    m = n % k
    if m == 0:
        print(i)
        exit(0)

print((-1))

# Optimized solution
k = int(eval(input()))

m = 0

for i in range(1, 10**6):
    n = m *10 +7
    m = n % k
    if m == 0:
        print(i)
        exit(0)

print((-1))
# Original solution
# coding: utf-8


def solve(*args: str) -> str:
    k = int(args[0])

    ret = 1
    a = 7 % k
    while(a):
        a = (a*10+7) % k
        ret += 1
        if k < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))


# Optimized solution
# coding: utf-8


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if k % 7 == 0 else k)
    if l % 2 == 0 or l % 5 == 0:
        return '-1'

    r = phi = l
    for i in range(2, int(-pow(l, 1/2))):
        if r % i == 0:
            phi = phi//i*(i-1)
            while r % i:
                r //= i

    a = 10 % l
    ret = 1
    while(a != 1):
        a = a*10 % l
        ret += 1
        if phi < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))
# Original solution
# coding: utf-8


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if k % 7 == 0 else k)
    if l % 2 == 0 or l % 5 == 0:
        return '-1'

    r = phi = l
    for i in range(2, int(-pow(l, 1/2))):
        if r % i == 0:
            phi = phi//i*(i-1)
            while r % i:
                r //= i

    a = 10 % l
    ret = 1
    while(a != 1):
        a = a*10 % l
        ret += 1
        if phi < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))


# Optimized solution
# coding: utf-8
from math import sqrt


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return '-1'

    r = phi = l
    for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi*(r-1)//r

    D = set()
    for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

    return str(ret)


if __name__ == "__main__":
    print((solve(*(open(0).read().splitlines()))))
# Original solution
K = int(eval(input()))

n = 7
ans = 0
i = 1
if K%2==0:
    ans = -1
else:
    while True:
        if n%K==0:
            ans = i
            break
        n *= 10
        n += 7
        n %= K
        i += 1
print(ans)

# Optimized solution
K = int(eval(input()))

n = 7
ans = -1
i = 1
if K%2==0:
    ans = -1
else:
    for i in range(K*2+10):
        if n%K==0:
            ans = i+1
            break
        n *= 10
        n += 7
        n %= K
print(ans)
# Original solution
K = int(eval(input()))
if K % 2 == 0:
    print('-1')
    exit()

i = 1
A = 7 % K
while A != 0:
    A = (10 * A + 7) % K
    i += 1
print(i)


# Optimized solution
K = int(eval(input()))
if K % 2 == 0 or K % 5 == 0:
    print('-1')
    exit()

A = 0
for i in range(K):
    A = (10 * A + 7) % K
    if A == 0:
        print((i+1))
        break
# Original solution
k = int(eval(input()))

if k % 2 == 0 or k % 5 == 0:
    print((-1))
elif k == 1 or k == 7:
    print((1))
else:
    t = 2
    ex = 77
    for i in range(10 ** 8):
        if ex % k == 0:
            break
        ex = (ex % k) * 10 + 7
        t += 1
    print(t)

# Optimized solution
k = int(eval(input()))


if k % 2 == 0 or k % 5 == 0:
    print((-1))
else:
    exc = 0
    for i in range(1, 10 ** 8):
        exc = exc * 10 + 7
        exc = exc % k
        if exc % k == 0:
            ans = i
            break
    print(ans)
# Original solution
import sys
K = int(eval(input()))

power = 7
SUM = 0

for i in range(1, 10 ** 6):
    SUM += power
    if SUM % K == 0:
        print(i)
        sys.exit()
    power *= 10
    power %= K

print((-1))

# Optimized solution
import sys
K = int(eval(input()))

L = 9 * K

if K % 7 == 0:
    L //= 7

power = 1

for i in range(1, 10 ** 6):
    power *= 10
    power %= L
    if power == 1:
        print(i)
        sys.exit()

print((-1))