Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

# a>b
dic = {}

def gcd(a, b):
    key = (a, b)
    if key in dic:
        return dic[key]
    ans = 0
    if b == 0:
        ans = a
    else:
        ans = gcd(b, a%b)
    dic[key] = ans
    return ans

def gcd_arr(arr):
    if len(arr)==1:
        return arr[0]
    i = len(arr)//2
    l, r = (gcd_arr(arr[:i]), gcd_arr(arr[i:]))
    return gcd(l, r) if l>r else gcd(r, l)

N = int(input())
As = [int(s) for s in input().split()]
ans = 1

for i in range(N):
    curr = None
    arr = [As[j] for j in range(N) if i!=j]
    ans = max(ans, gcd_arr(arr))

print(ans)

### FIXED CODE ###

from functools import reduce
from fractions import gcd

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(max(A))
else:
    left, right = [-1]*(N-1), [-1]*(N-1)
    lacc, racc = (A[0], A[-1])
    for i in range(N-1):
        lacc, racc = gcd(lacc, A[i]), gcd(racc, A[N-1-i])
        left[i], right[i] = lacc, racc
    ans = max(right[-1], left[-1])
    for l, r in zip(left[:-1], reversed(right[:-1])):
        ans = max(ans, gcd(l,r))
    print(ans)
### BUGGY CODE ###

import numpy as np

def main():
    N, W = map(int, input().split())
    dp = np.zeros(W+1, dtype=np.int16)
    for _ in range(N):
        w, v = map(int, input().split())
        np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
    print(dp[-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np

def main():
	N, W = map(int, input().split())
	dp = np.full(N * 1000 + 1, 10 ** 10, dtype=np.int64)
	dp[0] = 0
	for _ in range(N):
		w, v = map(int, input().split())
		np.minimum(dp[:-v] + w, dp[v:], out=dp[v:])
	print(((dp <= W) * np.arange(N * 1000 + 1)).max())

if __name__ == "__main__":
	main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

n = int(input())
A = [int(i) for i in input().split()]
d = {}

As = set(A)
for x in As:
    d.update({x: A.count(x)})

summ = 0
for x in As:
    y = d.get(x)
    summ += y*(y-1) // 2

for a0 in A:
    print(summ - (d.get(a0)-1))

### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(input())
A = [int(i) for i in input().split()]
d = {}

As = set(A)

for a in A:
    if a in d:
        d.update({a: d.get(a) + 1})
    else:
        d.update({a: 1})

summ = 0
for x in As:
    y = d.get(x)
    summ += y*(y-1) // 2

for a0 in A:
    print(summ - (d.get(a0)-1))
### BUGGY CODE ###

a,b,c,d,e,f = map(int, input().split())


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        if 0 < (a*i + b*j)*100 < f:
            for k in range(maxcd//c +1):
                for l in range(maxcd//d +1):
                    if (c*k + d*l <= (a*i + b*j)*e) and (a*i + b*j)*100+(c*k + d*l) <= f:
                        g = (c*k + d*l)/((a*i + b*j)*100+(c*k + d*l))
                        res.append([g,(a*i + b*j)*100+(c*k + d*l),(c*k + d*l)])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])

### FIXED CODE ###

a,b,c,d,e,f = map(int, input().split())


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        wa = a*i + b*j
        if 0 < wa*100 < f:
            for k in range(maxcd//c +1):
                for l in range(maxcd//d +1):
                    su = c*k + d*l
                    if (su <= wa*e) and wa*100+su <= f:
                        g = su/(wa*100+su)
                        res.append([g,wa*100+su,su])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])
### BUGGY CODE ###

n = int(raw_input())
d = [int(raw_input()) for i in range(n)]

if sum(d)%2 > 0:
    print(-1)
    exit()

d = sorted([(dd, i) for i, dd in enumerate(d)], reverse = True)
d_to_i = {dd:i for dd, i in d}
n_child = [1]*n
d_child = [0]*n
ans = []
for dd, i in d:
    d_i = dd+2*n_child[i]-n
    if d_i in d_to_i.keys():
        i_next = d_to_i[d_i]
        ans.append((i+1, i_next+1))
        n_child[i_next] += n_child[i]
        d_child[i_next] += d_child[i] + n_child[i]
        if n_child[i_next] == n:
            break
    else:
        print(-1)
        exit()

d_min, i_min = d[-1]
if d_min == d_child[i_min]:
    for i,j in ans:
        print str(i) + ' ' + str(j)
else:
     print(-1)


### FIXED CODE ###

n = int(input())
d = [int(input()) for i in range(n)]

if sum(d)%2 > 0:
    print(-1)
    exit()

d = sorted([(dd, i) for i, dd in enumerate(d)], reverse = True)
d_to_i = {dd:i for dd, i in d}
n_child = [1]*n
d_child = [0]*n
ans = []
for dd, i in d:
    d_i = dd+2*n_child[i]-n
    if d_i in d_to_i.keys():
        i_next = d_to_i[d_i]
        ans.append((i+1, i_next+1))
        n_child[i_next] += n_child[i]
        d_child[i_next] += d_child[i] + n_child[i]
        if n_child[i_next] == n:
            break
    else:
        print(-1)
        exit()

d_min, i_min = d[-1]
if d_min == d_child[i_min]:
    for a in ans:
        print(*a)
else:
     print(-1)
### BUGGY CODE ###

from functools import lru_cache


def popcnt(x):
    return bin(x).count("1")


@lru_cache(maxsize=None)
def rec(n):
    if n == 0:
        return 0
    else:
        return rec(n % popcnt(n)) + 1


n = int(input())
arr = input()

for i in range(n):
    x = arr[:i] + str(1 ^ int(arr[i])) + arr[i + 1:]
    print(rec(int(x, 2)))


### FIXED CODE ###

from functools import lru_cache


def popcnt(x):
    return bin(x).count("1")


@lru_cache(maxsize=None)
def rec(n):
    if n == 0:
        return 0
    else:
        return rec(n % popcnt(n)) + 1


ret = [rec(x) for x in range(2 * 10**5 + 1)]


n = int(input())
arr = input()

ALL_ARR = int(arr, 2)

cnt = popcnt(int(arr, 2))
init_big = ALL_ARR % (cnt + 1)
if cnt == 1:
    init_small = 0
else:
    init_small = ALL_ARR % (cnt - 1)


li = [0] * n
for i in range(n):
    if arr[i] == "0":
        li[i] = (init_big + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)
    elif ALL_ARR - (1 << (n - i - 1)) == 0 or cnt - 1 == 0:
        li[i] = "flg"
    else:
        li[i] = (init_small - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)


ans = []

for x in li:
    if x == "flg":
        ans.append(0)
    else:
        ans.append(ret[x] + 1)

print(*ans, sep="\n")
### BUGGY CODE ###

def solve():
    import sys
    input = sys.stdin.readline
    N,M,S = map(int,input().split())
    UVAB = [tuple(map(int,input().split())) for i in range(M)]
    CD = [tuple(map(int,input().split())) for i in range(N)]

    es = [[] for _ in range(N)]
    for u,v,a,b in UVAB:
        u,v = u-1,v-1
        es[u].append((v,a,b))
        es[v].append((u,a,b))

    INF = float('inf')
    times = [INF] * (2501 * N)
    start = min(2500,S)*N
    times[start] = 0
    hq = [start]
    ans = [-1] * N
    ans[0] = 0
    reached = set()
    import heapq
    heapq.heapify(hq)
    while hq:
        x = heapq.heappop(hq)
        t,v = divmod(x,N*2501)
        s,i = divmod(v,N)
        if ans[i] < 0:
            ans[i] = t
            reached.add(i)
            if len(reached) == N-1: break
        for to,a,b in es[i]:
            if a > s: continue
            nv = (s-a)*N + to
            if times[nv] <= t + b: continue
            times[nv] = t + b
            heapq.heappush(hq, (t+b)*N*2501 + nv)
        ns = s
        nt = times[v]
        while ns <= 2500:
            ns += CD[i][0]
            nt += CD[i][1]
            nv = min(2500,ns)*N + i
            if times[nv] <= nt: continue
            times[nv] = nt
            heapq.heappush(hq, nt*N*2501 + nv)
    print(*ans[1:], sep='\n')
solve()

### FIXED CODE ###

def solve():
    import sys
    input = sys.stdin.readline
    N,M,S = map(int,input().split())
    UVAB = [tuple(map(int,input().split())) for i in range(M)]
    CD = [tuple(map(int,input().split())) for i in range(N)]

    es = [[] for _ in range(N)]
    for u,v,a,b in UVAB:
        u,v = u-1,v-1
        es[u].append((v,a,b))
        es[v].append((u,a,b))

    INF = float('inf')
    times = [INF] * (2501 * N)
    start = min(2500,S)*N
    times[start] = 0
    hq = [start]
    ans = [-1] * N
    ans[0] = 0
    reached = 0
    import heapq
    heapq.heapify(hq)
    while hq:
        x = heapq.heappop(hq)
        t,v = divmod(x,N*2501)
        s,i = divmod(v,N)
        if ans[i] < 0:
            ans[i] = t
            reached += 1
            if reached == N-1: break
        for to,a,b in es[i]:
            if a > s: continue
            nv = (s-a)*N + to
            if times[nv] <= t + b: continue
            times[nv] = t + b
            heapq.heappush(hq, (t+b)*N*2501 + nv)
        ns = s
        nt = times[v]
        while ns <= 2500:
            ns += CD[i][0]
            nt += CD[i][1]
            nv = min(2500,ns)*N + i
            if times[nv] <= nt: break
            times[nv] = nt
            heapq.heappush(hq, nt*N*2501 + nv)
    print(*ans[1:], sep='\n')
solve()
### BUGGY CODE ###

inputLine=input()
N=int(inputLine.split(" ")[0])
M=int(inputLine.split(" ")[1])

inputLine=input()
H=inputLine.split(" ")
for i in range(len(H)):
    H[i]=int(H[i])

root=[]
for i in range(M):
    inputLine=input()
    A=int(inputLine.split(" ")[0])
    B=int(inputLine.split(" ")[1])

    root.append([A,B])
    root.append([B,A])

root.sort()    

allObservatoryCheck=[]
for i in range(N):
    allObservatoryCheck.append(True)

for i in range(N):

    for j in range(len(root)):
        
        if root[j][0] == i + 1:
            if H[i] <= H[root[j][1] - 1]:
                allObservatoryCheck[i] = False

        if root[j][0] > i + 1:
            break

result = 0
for i in range(N):
    if allObservatoryCheck[i] == True:
        result += 1

print(result)








### FIXED CODE ###

import bisect

inputLine=input()
N=int(inputLine.split(" ")[0])
M=int(inputLine.split(" ")[1])

inputLine=input()
H=inputLine.split(" ")
for i in range(len(H)):
    H[i]=int(H[i])

root=[]
for i in range(M):
    inputLine=input()
    A=int(inputLine.split(" ")[0])
    B=int(inputLine.split(" ")[1])

    root.append([A,B])
    root.append([B,A])

root.sort()

root2=[]
for i in range(len(root)):
    root2.append(root[i][0])

allObservatoryCheck=[]
for i in range(N):
    allObservatoryCheck.append(True)

for i in range(N):

    startPoint = bisect.bisect_left(root2, i + 1)

    for j in range(startPoint, len(root)):
        
        if root[j][0] == i + 1:
            if H[i] <= H[root[j][1] - 1]:
                allObservatoryCheck[i] = False

        if root[j][0] > i + 1:
            break

result = 0
for i in range(N):
    if allObservatoryCheck[i] == True:
        result += 1

print(result)
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
wa = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      wa +=gcd(i,j,l)
print(wa)

### FIXED CODE ###

import math

k = int(input())
wa = 0
aa = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    aa =math.gcd(i,j)
    for l in range(1,k+1):
      wa +=math.gcd(aa,l)
print(wa)
### BUGGY CODE ###

H,N = list(map(int,input().split()))
A, B = [], []
for _ in range(N):
  a,b = list(map(int,input().split()))
  A.append(a)
  B.append(b)
dp = [float("inf")] * (H+1)

for h in range(1, H+1):
  for i in range(N):
      if h - A[i] <= 0:
          dp[h] = min(dp[h], B[i])
      else:
          dp[h] = min(dp[h], B[i] + dp[h - A[i]])

print(dp[-1])

### FIXED CODE ###

H,N = list(map(int,input().split()))
dp = [float("inf")] * (H+1)

for i in range(N):
  a,b = list(map(int,input().split()))

  for h in range(1, H+1):
    if h - a <= 0:
      dp[h] = min(dp[h], b)
    else:
      dp[h] = min(dp[h], b + dp[h - a])

print(dp[-1])
### BUGGY CODE ###

import sys
# input処理を高速化する
input = sys.stdin.readline

N,X,Y = map(int,input().split())

# dp =[[0]*(N) for _ in range(N)]
# for j in range(N-1):
#     dp[j][j+1]=1
#     dp[j+1][j]=1

# # 線がついているところ
# dp[X-1][Y-1] = 1
# dp[Y-1][X-1] = 1

# print(*dp,sep="\n")

def dist(s,g):
    if s<=X and Y<=g:
        return X-s + 1 + g-Y
    elif s==X and g==Y:
        return 1
    else:
        return min(g-s,abs(s-X)+1+abs(g-Y))

for k in range(1,N):
    cnt =0

    if k==1:
        print(N)
    else:
        for i in range(1,N+1):
            for j in range(i+1,N+1):
                if dist(i,j) == k:
                    cnt+=1
        print(cnt)
    
         



### FIXED CODE ###

n,x,y = map(int,input().split())

x,y = x-1,y-1

d={}
for k in range(1,n):
    d[k]=0


for i in range(n):
    for j in range(i+1,n):
     
        dist=min(abs(i-j) , abs( i - x ) + 1 + abs(y - j) ,abs( i - y ) + 1 + abs(x - j))

        d[dist]+=1

for k in range(1,n):
    print(d[k])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

ans = 1

for i in range(n):
    ans *= a[i]

if ans > 10**18:
        ans =-1

print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

a = sorted(a)

ans = 1

for i in range(n):
  ans *= a[i]
  
  if ans == 0:
    break
  
  if ans > 10**18:
    ans = -1
    break

print(ans)
### BUGGY CODE ###

N=int(input())
P=[int(i) for i in input().split()]
count=1
for i in range(1,N):
    if P[i]<=min(P[:i]):
        count+=1
print(count)


### FIXED CODE ###

N=int(input())
P=[int(i) for i in input().split()]
count=1
min=P[0]
for i in range(1,N):
    if min>=P[i]:
        count+=1
        min=P[i]
    else:
        continue
print(count)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

for i in range(1, N+1):
    print(A.count(i))

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))

c = collections.Counter(A)
for i in range(1, N+1):
    print(c[i])
### BUGGY CODE ###

prime = []
is_prime = []
is_prime.append(False)
is_prime.append(False)

def sieve(r):
    start = len(is_prime)
    if start >= r:
        return 

    for i in range(start, r + 1):
        is_prime.append(True)

    for i in prime:
        j = 2 * i
        while j <= r:
            if j < start:
                j = j + i
                continue

            is_prime[j] = False
            j = j + i

    for i in range(start, r + 1):
        if is_prime[i]:
            prime.append(i)

            j = 2 * i
            while j <= r:
                is_prime[j] = False
                j = j + i

def main():
    answers = []
    Q = int(input())
    for i in range(Q):
        l, r = map(int, input().split())
        sieve(r)
        like_numbers = [n for n in prime if n % 2 == 1 and l <= n <= r and is_prime[(n + 1) // 2]]
        answers.append(len(like_numbers))
    
    for answer in answers:
        print(answer)

main()

### FIXED CODE ###

# D - 2017-like Number
# https://atcoder.jp/contests/abc084/tasks/abc084_d

counts = []
counts.append(0)
counts.append(0)
counts.append(0)

prime = []

is_prime = []
is_prime.append(False)
is_prime.append(False)

def sieve(r):
    for i in range(2, r + 1):
        is_prime.append(True)

    for i in range(2, r + 1):
        if is_prime[i]:
            prime.append(i)

            j = 2 * i
            while j <= r:
                is_prime[j] = False
                j = j + i

def calc_like_number_count(r):
    for i in range(3, r + 1):
        if i % 2 == 1 and is_prime[i] and is_prime[(i + 1) // 2]:
            counts.append(1)
        else:
            counts.append(0)
    
    for i in range(3, r + 1):
        counts[i] = counts[i] + counts[i - 1]


def main():
    Q = int(input())
    querys = []
    max_r = 0
    for i in range(Q):
        l, r = map(int, input().split())
        querys.append((l, r))
        if max_r < r:
            max_r = r

    sieve(max_r)
    calc_like_number_count(max_r)

    for l, r in querys:
        print(counts[r] - counts[l - 1])
    
main()
### BUGGY CODE ###

T = int(input())

for i in range(T):
  a, b, c, d = map(int, input().split())
  if d<b or a<b:
    print('No')
    continue
  if b-1<=c:
    print('Yes')
    continue
  if d%b<b-c and  d%b!=0:
    print('No')
    continue
  visited=[]
  while True:
    a = c+(a-c)%b
    if a>c and a<b:
      print('No')
      break
    elif a == c:
      if c in visited:
        print('Yes')
        break
      visited.append(a)
    else:
      a = a-b
      if a in visited:
        print('Yes')
        break
      visited.append(a)
    a+=d



### FIXED CODE ###

import fractions
T = int(input())

for i in range(T):
  a, b, c, d = map(int, input().split())

  if d<b or a<b:
    print('No')
    continue

  if b-1<=c:
    print('Yes')
    continue

  gcd=fractions.gcd(d,b)
  e=b-gcd+a%gcd
  if e>c:
    print('No')
  else:
    print('Yes')
### BUGGY CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    a.sort(reverse=True)
    a[0]=a[0]//2
print(sum(a))


### FIXED CODE ###

import heapq
def _heappush_max(heap,item):
  heap.append(item)
  heapq._siftdown_max(heap,0,len(heap)-1)
def _heappop_max(heap):
  lastelt=heap.pop()
  if heap:
    returnitem=heap[0]
    heap[0]=lastelt
    heapq._siftup_max(heap,0)
    return returnitem
  return lastelt

n,m=map(int,input().split())
a=list(map(int,input().split()))
heapq._heapify_max(a)
for i in range(m):
    _heappush_max(a,_heappop_max(a)//2)
print(sum(a))
### BUGGY CODE ###

# coding: utf-8
from itertools import count

def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = [None]*(n1+1), [None]*(n2+1)
  for i in range(n1):
    L[i] = A[left + i]
  for i in range(n2):
    R[i] = A[mid + i]
  L[n1] = R[n2] = float("inf")
  i = j = 0
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
  counter += right - left
def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)

### FIXED CODE ###

def merge(A, left, mid, right):
  global counter
  n1, n2 = mid - left, right - mid
  L, R = list(A[left:left+n1]+[float("inf")]), list(A[mid:mid+n2]+[float("inf")])
  i = j = 0
  for k in range(left, right):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
  counter += right - left
def mergeSort(A, left, right):
  if left+1 < right:
    mid = (left + right)//2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

N = int(input())
A = [int(i) for i in input().split()]
counter = 0
mergeSort(A, 0, len(A))
print(*A)
print(counter)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))

count=1
for i in A:
    print(A.count(count))
    count+=1

print(0)

### FIXED CODE ###

import collections
 
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
for i in range(1, N+1):
    print(cnt[i])
### BUGGY CODE ###

s = list(input().strip())
N = len(s)
a = ""
for i in range(N):
    if s[i]!="x":
        a += s[i]
if a==a[::-1]:
    flag = 1
else:
    flag = 0
if flag==1:
    y = list(s[:])
    cur = 0
    cnt = 0
    while True:
        if y[cur]==y[len(y)-1-cur]:
            cur += 1
        else:
            cnt += 1
            if y[cur]=="x":
                y = y[:len(y)-cur]+["x"]+y[len(y)-cur:]
            else:
                y = y[:cur]+["x"]+y[cur:]
        if y==y[::-1]:break
if flag==0:
    print(-1)
else:
    print(cnt)

### FIXED CODE ###

import math
s = input().strip()
A = []
B = [0 for _ in range(len(s)+1)]
y = ""
for i in range(len(s)):
    if s[i]!="x":
        y += s[i]
        A.append(i)
        B[i+1] = B[i]
    else:
        B[i+1] = B[i]+1
flag=0
cnt = 0
for i in range(len(y)//2):
    if y[i]!=y[-(i+1)]:
        flag = 1
        cnt = -1
        break
if flag==0 and len(y)>0:
    if B[A[0]]!=B[-1]-B[A[-1]]:
        cnt += abs(B[A[0]]-(B[-1]-B[A[-1]]))
    for i in range(1,math.ceil(len(A)/2)):
        if B[A[i]]-B[A[i-1]] != B[A[-i]]-B[A[-(i+1)]]:
            cnt += abs(B[A[i]]-B[A[i-1]]-(B[A[-i]]-B[A[-(i+1)]]))
print(cnt)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():    
    mod=10**9+7
    N,M=MI()
    adj=[[]for _ in range(N)]
    
    for i in range(M):
        a,b=MI()
        a-=1
        b-=1
        adj[a].append(b)
    
    import queue
    use=[0]*N

    
    def bfs(a):
        #a=>aの最短距離を求める
        q=queue.Queue()
        q.put((a,-1,0))
        use[a]=1
        for i in range(N):
            use[i]=0
        
        while not(q.empty()):
            v,p,d=q.get()
            
            for nv in adj[v]:
                if nv==a:
                    return d+1
                else:
                    if nv!=p:
                        if use[nv]==0:
                            use[nv]=1
                            q.put((nv,v,d+1))
                            
        return -1
    
    def bfs2(a):
        #aからaまでの
        #経路復元も
        P=[-1]*N
        q=queue.Queue()
        q.put((a,-1,0))
        for i in range(N):
            use[i]=0
        use[a]=1
        flag=0
        
        while not(q.empty()):
            if flag:
                break
            v,p,d=q.get()
            #print(v,p,d)
            P[v]=p

            for nv in adj[v]:
                #print("nv:",nv)
                if nv==a:
                    flag=1
                    break
                if nv!=p:
                    if use[nv]==0:
                        use[nv]=1
                        q.put((nv,v,d+1))
                            
        L=[]
        flag=1
        for i in range(N):
            #print(v)
            L.append(v)
            v=P[v]
            if v==a:
                L.append(a)
                break
        return L
        
                        
                        
        

    
    ans=N+1
    ansi=0

    for i in range(N):#全ての辺をなめる
        temp=bfs(i)#ここはab間の最短距離をbfsで求める
        if temp!=-1:
            if temp<ans:
                ans=temp
                ansi=i

    
    if ans==N+1:
        print(-1)
    else:
        print(ans)
        ans=bfs2(ansi)
        for i in ans:
            print(i+1)
        
        
        

main()


### FIXED CODE ###

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)

ret = [0] * (n + 1)
for start in range(n):
    parent = [-1] * n
    q = [start]
    while len(q) > 0:
        i = q.pop(0)
        for j in edges[i]:
            if j == start:
                loop = [i]
                while i != start:
                    i = parent[i]
                    loop.append(i)
                if len(ret) > len(loop):
                    ret = loop
                break
            if parent[j] == -1:
                parent[j] = i
                q.append(j)

if len(ret) > n:
    print(-1)
else:
    print(len(ret))
    for i in reversed(ret):
        print(i + 1)