Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02813 (python)

Fixed submission:
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
a = 0
b = 0
k = 0

for i in itertools.permutations(range(1,n+1)):
    k += 1
    if i == p:
        a = k
    if i == q:
        b = k
ans = abs(a-b)
print(ans)

Buggy submission (verdict: Runtime Error):
 from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
a = 0
b = 0
k = 0

for i in itertools.permutations(range(1,n+1)):
    k += 1
    if i == p:
        a = k
    if i == q:
        b = k
ans = abs(a-b)
print(ans)
Problem p02882 (python)

Fixed submission:
import numpy as np

a, b, x = map(float, input().split())
ans = 0
if a*a*b > 2*x:
    ans =180.0/np.pi*np.arctan((a*b*b)/(2*x))
else:
    ans = 180.0/np.pi*np.arctan((2*(a*a*b-x))/a**3)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

a, b, x = map(int, input().split())
ans = 0
if a*a*b > 2*x:
    ans =180.0/np.pi*math.atan((a*b*b)/(2*x))
else:
    ans = 180.0/np.pi*math.atan((2*(a*a*b-x))/a**3)

print(ans)
Problem p02900 (python)

Fixed submission:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

[A,B] = inpl()

def gcd(a,b):
    if a < b: return gcd(b,a)
    else: 
        return gcd(b,a%b) if b != 0 else a

ans_dq = deque([1])

c = gcd(A,B)
for i in range(2,int(c**0.5)//1+1):
    add_or_not = 0
    while c%i == 0:
        c = c//i
        add_or_not = 1
    if add_or_not: ans_dq.append(i)
if c != 1: ans_dq.append(c)

ans = len(ans_dq)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0

def num_check(n,a,b):
    just_list = list(range(2,n+1))
    ans_dq = deque([1])
    while len(just_list)!=0:
        first_val = just_list[0]
        ans_dq.append(first_val)
        just_list = [i for i in just_list if (i%first_val != 0 and a%i == 0 and b%i == 0)]
    return len(ans_dq)

def gcd(a,b):
    if b>a: return gcd(b,a)
    else: return gcd(b,a%b) if a%b else b

[a,b] = inpl()
n = gcd(a,b)
ans = num_check(n,a,b)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0

def num_check(n,a,b):
    just_list = list(range(2,n+1))
    ans_dq = deque([1])
    while len(just_list)!=0:
        first_val = just_list[0]
        ans_dq.append(first_val)
        just_list = [i for i in just_list if (i%first_val != 0 and a%i == 0 and b%i == 0)]
    return len(ans_dq)

def gcd(a,b):
    if b>a: return gcd(b,a)
    else: return gcd(b,a%b) if a%b else b

[a,b] = inpl()
n = gcd(a,b)
ans = num_check(int(n),a,b)
print(ans)
Problem p02972 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
b = [0] * n
 
for i in range(n, 0, -1):
    if sum(b[i-1::i]) % 2 == a[i-1]:
        continue
    else:
        b[i-1] = 1
 
c = []
for i in range(n):
    if b[i] == 1:
        c.append(i+1)
print(sum(b))
if len(c) > 0:
    print(*c)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())




N = int(input())
alist = list(map(int, input().split()))
ans_list = []

for i in range(N, 0, -1):
    if i > N//2:
        if alist[i-1]:
            ans_list.append(i)
    else:
        if sum(alist[i-1::i])%2 != alist[i-1]:
            ans_list.append(i)
print(len(ans_list))
if len(ans_list >0):
    print(*ans_list)
Problem p03160 (python)

Fixed submission:
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = int(input())
h_list = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h_list[1]-h_list[0])

for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h_list[i]-h_list[i-1]), dp[i-2]+abs(h_list[i]-h_list[i-2]))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
h_list = list(map(int, input().split()))
dp = [0]*n

for i in range(1,n):
    temp = []
    for j in range(1,min(k,i)+1):
        temp.append(dp[i-j]+abs(h_list[i]-h_list[i-j]))
        dp[i] = min(temp)

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
#from collections import defaultdict, deque
#import sys, heapq, bisect, math, itertools, string, queue, copy, time
#from fractions import gcd
#import numpy as np
#sys.setrecursionlimit(10**8)
#INF = float('inf')
#MOD = 10**9+7
#EPS = 10**-7
#def inp(): return int(sys.stdin.readline())
#def inpl(): return list(map(int, sys.stdin.readline().split()))
#def inpl_str(): return list(sys.stdin.readline().split())

n, k = map(int, input().split())
h_list = list(map(int, input().split()))
dp = [0]*n

for i in range(1,n):
    temp = []
    for j in range(1,min(k,i)+1):
        temp.append(dp[i-j]+abs(h_list[i]-h_list[i-j]))
        dp[i] = min(temp)

print(dp[n-1])
Problem p03086 (python)

Fixed submission:
def main():
    s = input()
    ans = [0]
    count = 0
    for char in s:
        if char in ["A", "C", "G", "T"]:
            count += 1
        else:
            ans.append(count)
            count = 0
    ans.append(count)
    print(max(ans))

if __name__ == '__main__':
   main()

Buggy submission (verdict: Runtime Error):
def main():
    s = input()
    ans = []
    count = 0
    for char in s:
        if char in ["A", "C", "G", "T"]:
            count += 1
        else:
            ans.append(count)
            count = 0
    print(max(ans))

if __name__ == '__main__':
   main()
Problem p03206 (python)

Fixed submission:
D = input()

if D == "25":
    print("Christmas\n")
elif D == "24":
    print("Christmas Eve\n")
elif D == "23":
    print("Christmas Eve Eve\n")
else:
    print("Christmas Eve Eve Eve\n")

Buggy submission (verdict: Runtime Error):
n = int(input())
p = [int(input()) for i in range(n)]

print(int(sum(p)-max(p)/2))

Buggy submission (verdict: Runtime Error):
D = input()

if D == 25:
    print("Christmas")
elif D == 24:
    print("Christmas Eve")
elif D == 23:
    print("Christmas Eve Eve")
elif:
    print("Christmas Eve Eve Eve")
Problem p03399 (python)

Fixed submission:
a, b, c, d = map(int, [input() for i in range(4)])
print(min([a, b]) + min([c, d]))

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = list(map(int, input().split()))


    a.append(0)
    a.insert(0, 0)
    costs = []
    for i in range(n + 1):
        costs.append(abs(a[i + 1] - a[i]))

    s = sum(costs)
    for i in range(n):
        print(s - costs[i] - costs[i + 1] + abs(a[i] - a[i + 2]))

main()

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    b = 0
    bud = 0
    for ai in a:
        if a[i] != ai:
            bud += abs(ai - b)
            b = ai
    bud += abs(b)
    print(bud)
Problem p03401 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0, 0)
costs = []
for i in range(n + 1):
    costs.append(abs(a[i + 1] - a[i]))

s = sum(costs)
for i in range(n):
    print(s - costs[i] - costs[i + 1] + abs(a[i] - a[i + 2]))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0, 0)
costs = []
for i in xrange(n + 1):
    costs.append(abs(a[i + 1] - a[i]))
s = sum(costs)
for i in xrange(n):
    print(s - costs[i] - costs[i + 1] + abs(a[i] - a[i + 2]))
Problem p03494 (python)

Fixed submission:
import math
n = input()
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(round(ans))

Buggy submission (verdict: Runtime Error):
import math
n = input()
a = list(map(int, input().split()))
ans = float('inf')
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).refind('1') - 1)

Buggy submission (verdict: Runtime Error):
import math
n = input()
a = list(map(int, input().split()))
ans = float('inf')
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).refind('1') - 1)
Problem p02612 (python)

Fixed submission:
N = int(input())
while N > 1000:
  N = N - 1000
N = 1000 - N
print(N)

Buggy submission (verdict: Runtime Error):
a = 0
while N >= 1000:
  N = N - 1000
else:
  a += N
print(a)

Buggy submission (verdict: Runtime Error):
my_result = 0
while N >= 1000:
    N = N - 1000
else:
    my_result += N
return my_result
Problem p02621 (python)

Fixed submission:
a = int(input())
my_result = a + a**2 + a**3
print(my_result)

Buggy submission (verdict: Runtime Error):
a = input()
my_result = a + a*a + a*a*a
print(my_result)

Buggy submission (verdict: Runtime Error):
a = input()
my_result = a + a**2 + a**3
print(my_result)

Buggy submission (verdict: Runtime Error):
a = int(input())
my_result = a + a**2 + a ***3
my_result
Problem p02705 (python)

Fixed submission:
N = int(input())
my_result = N * 2 * 3.14159265
print(my_result)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
my_result = N * np(pi)
print(my_result)
Problem p02981 (python)

Fixed submission:
a, b, c = list(map(int, input().split()))
if a * b >= c:
  print(c)
else:
  print(a * b)

Buggy submission (verdict: Runtime Error):
a, b, c = list(map(intl, input().split()))
if a * b >= c:
  print(c)
else:
  print(a * b)
Problem p03101 (python)

Fixed submission:
a = [list(map(int, input().split())) for i in range(2)]
H = a[0][0] 
W = a[0][1] 
h = a[1][0] 
w = a[1][1] 
my_result = H * W - h * W - H * w + h * w
print(my_result)

Buggy submission (verdict: Runtime Error):
a = [list(map(int, input().split())) for i in range(2)]
a[0][0] = H
a[0][1] = W
a[1][0] = h
a[1][1] = w
my_result = H * W - h * W - H * w + h * w
print(my_result)
Problem p03337 (python)

Fixed submission:
a, b = list(map(int, input().split()))
my_result = max(a + b, a - b, a * b)
print(my_result)

Buggy submission (verdict: Runtime Error):
a, b, c = list(map(int, input().split()))
my_result = max(a+b, a-b, a*b)
print(my_result)
Problem p03433 (python)

Fixed submission:
a = [int(input()) for i in range(2)]
n = a[0] % 500
if a[1] >= n:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a = [int(input()) for i in range(2)]
n = a[0] % 500
if a >= n:
  print('Yes')
else:
  print('No')
Problem p03469 (python)

Fixed submission:
s = input()
s_2 = s[4:10]
print('2018' + s_2)

Buggy submission (verdict: Runtime Error):
s = input()
s[3] = '8'
print(s)
Problem p03555 (python)

Fixed submission:
x = [input() for i in range(2)]
if x[0][0] == x[1][2] and x[0][1] == x[1][1] and x[1][0] == x[0][2]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
x = [list(map(str, input().split())) for i in range(2)]
if x[0][0] == x[1][2] and x[0][1] == x[1][1] and x[1][0] == x[0][2]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == b[2] and a[1] == b[1] and a[2] == b[0]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
a = [list(map(str, input().split())) for i in range(2)]
if a[0][0] == a[1][2] and a[0][1] == a[1][1] and a[0][2] == a[1][0]:
  print('YES')
else:
  print('NO')
Problem p03737 (python)

Fixed submission:
a, b, c = list(map(str, input().split()))
print(a[0].upper() + b[0].upper() + c[0].upper())

Buggy submission (verdict: Runtime Error):
a, b, c = list(map(str, input().split()))
print(a[0].upper() + a[1].upper() + a[2].upper())

Buggy submission (verdict: Runtime Error):
a, b, c = list(map(int, input().split()))
print(a[0].upper() + a[1].upper() + a[2].upper())
Problem p02609 (python)

Fixed submission:
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c


N = int(input())
X = input()
pc = X.count('1')
if pc == 0:
    for i in range(N):
        print(1)
elif pc == 1:
    if X[-1] == '1':
        for i in range(N-1):
            print(2)
        print(0)
    else:
        for i in range(N-1):
            if X[i] == '1':
                print(0)
            else:
                print(1)
        print(2)
else:
    modX1 = 0
    modX2 = 0
    Xi = [None] * N
    x1 = 1
    x2 = 1
    for i in range(N):
        if X[-i-1] == '1':
            Xi[-i-1] = x1
            modX1 = (modX1+x1) % (pc-1)
            modX2 = (modX2+x2) % (pc+1)
        else:
            Xi[-i-1] = x2
        x1 = x1 * 2 % (pc-1)
        x2 = x2 * 2 % (pc+1)
    for i in range(N):
        ans = 1
        x = (modX1 - Xi[i]) % (pc-1) if X[i] == '1' else (modX2 + Xi[i]) % (pc+1)
        while x != 0:
            x = x % popcnt(x)
            ans += 1
        print(ans)

Buggy submission (verdict: Runtime Error):
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c


N = int(input())
X = input()
pc = X.count('1')
modX1 = 0
modX2 = 0
Xi = [None] * N
x1 = 1
x2 = 1
for i in range(N):
    if X[-i-1] == '1':
        Xi[-i-1] = x1
        modX1 = (modX1+x1) % (pc-1)
        modX2 = (modX2+x2) % (pc+1)
    else:
        Xi[-i-1] = x2
    x1 = x1 * 2 % (pc-1)
    x2 = x2 * 2 % (pc+1)
for i in range(N):
    ans = 1
    x = (modX1 - Xi[i]) % (pc-1) if X[i] == '1' else (modX2 + Xi[i]) % (pc+1)
    while x != 0:
        x = x % popcnt(x)
        ans += 1
    print(ans)
Problem p02741 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())-1
print(l[K])

# a, b, c = input(), input(), input()
# la, lb, lc = len(a), len(b), len(c)
# for i in range(1, min(la, lb)):
#     S = ''
#     for j in range(i):
#         if a[la-i+j] == b[j]:
#             S += b[j]
#             continue
#         elif a[la-i+j] == '?':
#             S += b[j]
#         elif b[j] == '?':
#             S += c[j]

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

a, b, c = map(int, input().split())
if a*a+b*b+c*c > 2*(a*b+b*c+c*a) and c > 4:
    print('Yes')
else:
    print('No')
Problem p02768 (python)

Fixed submission:
n,a,b=map(int,input().split())
m=10**9+7
def com(n,k,m):
  p,q=1,1
  for i in range(n-k+1,n+1):
    p*=i
    p%=m
  for i in range(1,k+1):
    q*=i
    q%=m
  return p*pow(q,m-2,m)%m
ca,cb=com(n,a,m),com(n,b,m)
ans=(pow(2,n,m)-1-ca-cb)%m
print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
m=10**9+7
def com(n,k,m):
  p,q=1,1
  for i in range(n-k,n+1):
    p*=i
    p%=m
  for i in range(1,k+1):
    q*=i
    q%=m
  return p*pow(q,m-2,m)%m
ans=(pow(2,n,m)-ca-cb)%m
Problem p02772 (python)

Fixed submission:
n=int(input())
a=[int(x) for x in input().split()]
flg=0
for x in a:
  if x%2==0 and x%3 and x%5:
    flg=1
if flg:
  print("DENIED")
else:
  print("APPROVED")

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(x) for x in input().input()]
flg=0
for x in a:
  if x%2==0 and x%3 and x%5:
    flg=1
if flg:
  print("DENIED")
else:
  print("APPROVED")
Problem p02811 (python)

Fixed submission:
k, x = map(int, input().split())
if 500*k >= x:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = input()
print(input().count("ABC"))

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
if 500*k >= X:
  print("Yes")
else:
  print("No")
Problem p02812 (python)

Fixed submission:
n = input()
print(input().count("ABC"))

Buggy submission (verdict: Runtime Error):
n = input()
print(inpur().count("ABC"))
Problem p02854 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
allL = sum(A)
L, mL = 0, float('inf')
for i in range(N):
    L += A[i]
    if abs(2*L-allL) < mL:
        mL = abs(2*L-allL)
    else:
        break
print(mL)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
S = sum(A)
L = A[0]
m = S-L
k = 1
for i in range(1, N-1):
  L += A[i]
  if S-L < m:
    k = i+1
print(abs(S-2*sum(A[:k]))
Problem p02866 (python)

Fixed submission:
from collections import Counter
MOD = 998244353

N = int(input())
D = list(map(int, input().split()))
C = Counter(D)
if D[0] != 0 or C[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1, max(D)+1):
    if C[i] == 0:
        ans = 0
        break
    else:
        ans *= pow(C[i-1], C[i], MOD)
        ans %= MOD
print(ans)


# import sys
# sys.setrecursionlimit(10000000)
# def input():
#     return sys.stdin.readline()[:-1]
# from bisect import *
# from collections import *
# from heapq import *
# import functools
# import itertools
# import math
# INF = float('inf')
# # MOD = 10**9+7
# MOD = 998244353
#
# N = int(input())
# D = list(map(int, input().split()))
# if D[0] != 0:
#     print(0)
# C = Counter(D)
# ans = 1
# for i in range(1, max(D)+1):
#     if C[i] == 0:
#         ans = 0
#         break
#     else:
#         ans *= pow(C[i-1], C[i], MOD)
#         ans %= MOD
# print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
C = Counter(D)
ans = 1
for i in range(1, max(D)+1):
    if C[i] == 0:
        ans = 0
        break
    else:
        ans *= pow(C[i-1], C[i], MOD)
        ans %= MOD
print(ans)
Problem p02902 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
import itertools
import math
INF = 10**9
MOD = 10**9+7

N, M = map(int, input().split())
es = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    es[a].append(b)
ansr, ansd = -1, INF
for r in range(1, N+1):
    d = [INF] * (N+1)
    d[0] = 0
    dq = deque()
    for w in es[r]:
        dq.append(w)
        d[w] = 1
    while len(dq) > 0:
        v = dq.popleft()
        if v == r:
            break
        nd = d[v]+1
        for u in es[v]:
            if nd < d[u]:
                d[u] = nd
                dq.append(u)
    if d[r] < ansd:
        ansd = d[r]
        ansr = r
if ansr == -1:
    print(-1)
else:
    vis = [0] * (N+1)
    vis[0] = 1
    p = [-1] * (N+1)
    dq = deque()
    for v in es[ansr]:
        vis[v] = 1
        p[v] = 0
        dq.append(v)
    while len(dq) > 0:
        v = dq.popleft()
        if v == ansr:
            break
        for u in es[v]:
            if vis[u] == 0:
                vis[u] = 1
                p[u] = v
                dq.append(u)
    lst = []
    v = ansr
    while p[v] != -1:
        lst.append(v)
        v = p[v]
    print(len(lst))
    print(*lst, sep = '\n')

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
import itertools
import math
INF = 10**9
MOD = 10**9+7

def dfs(v):
    vis[v] = 0
    for u in es[v]:
        if vis[u]:
            k = dfs(u)
            if k != -1:
                return k
            vis[u] = 1
        else:
            return u
    return -1

N, M = map(int, input().split())
es = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    es[a-1].append(b-1)
flg = 0
lst = list(range(N))
ans = -1
for i in range(N):
    for w in lst:
        vis = [1] * N
        s = dfs(w)
        if s != -1:
            flg = 1
            dq = deque()
            p = [-1] * N
            for v in es[s]:
                dq.append(v)
                p[v] = s
            while len(dq) > 0:
                v = dq.popleft()
                if v == s:
                    break
                for u in es[v]:
                    if p[u] == -1:
                        dq.append(u)
                        p[u] = v
            tmp = [s+1]
            v = p[v]
            while v != s:
                tmp.append(v+1)
                v = p[v]
            if ans == -1 or len(tmp) < len(ans):
                ans = tuple(tmp)
                lst = tmp[1:]
if flg:
    print(len(ans))
    print(*ans, sep = '\n')
else:
    print(-1)