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

n,m,q= map(int,input().split())
lrList=[list(map(int,input().split()))for i in range(m)]
pqList=[list(map(int,input().split()))for i in range(q)]
for pq in pqList:
    ans = 0
    for lr in lrList:
        if pq[0] <= lr[0] and pq[1] >= lr[1]:
            ans +=1
    print(ans)


### FIXED CODE ###

n,m,q= map(int,input().split())
dataList = [[0 for xIndex in range(n+1)]for yIndex in range(n+1)]

for i in range(m):
    xTemp,yTemp = map(int,input().split())
    dataList[yTemp][xTemp]+=1
pqList=[list(map(lambda x:int(x),input().split()))for i in range(q)]
for yIndex in range(1,n+1):
    for xIndex in range(1,n+1):
        dataList[yIndex][xIndex]+=dataList[yIndex][xIndex-1]
for yIndex in range(1,n+1):
    for xIndex in range(1,n+1):
        dataList[yIndex][xIndex]+=dataList[yIndex-1][xIndex]

for pq in pqList:
    p = pq[0]-1
    q = pq[1]
    print(dataList[q][q]+dataList[p][p]-dataList[p][q]-dataList[q][p])
### BUGGY CODE ###

N = int(input())
S = input()

S1,S2 = S[:N],S[N:][::-1]

from itertools import product
B = list(product([0,1], repeat=N))

D1 = {}
Ans = 0

for bb in B:
    red,blue = "",""
    cnt = 0
    for i,b in enumerate(bb):
        if b == 0:
            red += S1[i]
            cnt += 1
        else:
            blue += S1[i]
    key = (cnt,red+blue[::-1])
    if key not in D1.keys():
        D1[key] = 1
    else:
        D1[key] += 1

for bb in B:
    red,blue = "",""
    cnt = 0
    for i,b in enumerate(bb):
        if b == 1:
            red += S2[i]
            cnt += 1
        else:
            blue += S2[i]
    key = (cnt,red+blue[::-1])
    if key in D1.keys():
        Ans += D1[key]

print(Ans)

### FIXED CODE ###

N = int(input())
S = input()

S1,S2 = S[:N],S[N:][::-1]

dic = {}
Ans = 0
keys = []

for i in range(2**N):
    red,blue = "",""
    red2,blue2 = "",""
    bits = bin(2**N+i)[3:]
    for j in range(N):
        if bits[j]=="0":
            red   += S1[j]
            red2 += S2[j]
        else:
            blue += S1[j]
            blue2 += S2[j]
    keys.append(red2+"-"+blue2)
    key = red+"-"+blue
    if key not in dic.keys():
        dic[key] = 1
    else:
        dic[key] += 1

for k in keys:
    Ans += dic.get(k,0)

print(Ans)
### BUGGY CODE ###

X, Y, A, B, C = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
no = list(map(int, input().split()))

red = sorted(red, reverse=True)[:X]
green = sorted(green, reverse=True)[:Y]
no = sorted(no, reverse = True)[:X+Y]

for i in range(len(no)):
    minX = min(red)
    minY = min(green)
    
    if no[i]>minX or no[i]>minY:
        if minX<=minY:
            red[red.index(minX)] = no[i]
        else:
            green[green.index(minY)] = no[i]
    else:
        break
        
print(sum(red)+sum(green))

### FIXED CODE ###

X, Y, A, B, C = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
no = list(map(int, input().split()))

red = sorted(red, reverse=True)[:X]
green = sorted(green, reverse=True)[:Y]
no = sorted(no, reverse = True)[:X+Y]

co = sorted(red+green)

for i in range(len(no)):
    if no[i]>co[i]:
        co[i] = no[i]
    else:
        break
        
print(sum(co))
### BUGGY CODE ###

# 二部グラフかどうかの判定法
import sys
n=int(input())
s=[list(input()) for _ in range(n)]
g=[[] for _ in range(n+1)]
for i in range(n):
    for j in range(i+1,n):
        if s[i][j]=="1":
            g[i+1].append(j+1)
            g[j+1].append(i+1)
#二部グラフかどうかの判定
flag=[-1]*(n+1)
forest=[]
for i in range(1,n+1):
    U=[]
    if flag[i]==-1:
        que=[[i]]
        j=1
        flag[i]=1
        while que:
            h=que.pop()
            H=[]
            for u in h:
                flag[u]=j%2
                U.append(u)
                for v in g[u]:
                    if flag[v]==-1:
                        H.append(v)
                        flag[v]=(j+1)%2
                    elif flag[v]==j%2:
                        print(-1)
                        sys.exit()
            if H:
                que.append(H)
            j+=1
    if U:
        forest.append(U)
#iからjまでの距離を求めていく。
sum=0
for lst in forest:
    m=0
    for i in lst:
        for j in lst:
            if i>=j:
                continue
            que=[[i]]
            flag=[0]*(n+1)
            flag[i]=1
            k=0
            while que:
                k+=1
                h=que.pop()
                H=[]
                for u in h:
                    if u==j:
                        break
                    for v in g[u]:
                        if flag[v]==0:
                            H.append(v)
                            flag[v]=1
                else:
                    if H:
                        que.append(H)
                    continue
                break
            m=max(m,k)
    sum+=m            
print(sum)

### FIXED CODE ###

import sys
n=int(input())
data=[[] for i in range(n+1)]
for i in range(1,n+1):
    s=[None]+list(input())
    for j in range(1,n+1):
        if s[j]=="1":
            data[i].append(j)

#二部グラフ判定
flag=[-1]*(n+1)
for i in range(1,n+1):
    if flag[i]==-1:
        que=[[i]]
        flag[i]=0
        k=1
        while que[0]:
            h=que[0]
            H=[]
            for u in h:
                for v in data[u]:
                    if flag[v]==-1:
                        flag[v]=k
                        H.append(v)
                    else:
                        if flag[v]==k:
                            continue
                        else:
                            print(-1)
                            sys.exit()
            k=(k+1)%2
            que=[H]

#washall
inf=float("inf")
d=[[inf]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    d[i][i]=0
for i in range(1,n+1):
    for u in data[i]:
        d[i][u]=1
for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        ans=max(ans,d[i][j])

print(ans+1)
### BUGGY CODE ###

# Prime Number

import sys


def count_prime_numer(n):
	if n <= 1:
		return 0
	elif n == 2:
		return 1
	else:
		count = 1
		for prime in xrange(3, n + 1, 2):
			for i in xrange(3, prime - 1):
				if prime % i == 0:
					break
			else:
				count += 1
		return count

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	print count_prime_numer(data)

### FIXED CODE ###

# Prime Number

import sys


MAX_NUM = 1000000
ROOT_MAX_NUM = 1000

primes = [1] * MAX_NUM

primes[0] = primes[1] = 0

for i in xrange(2, ROOT_MAX_NUM):
	if not primes[i]:
		continue
	for j in xrange(i+i, MAX_NUM, i):
		primes[j] = 0

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	count = 0
	for i in xrange(data+1):
		if primes[i]:
			count += 1
	print count
### BUGGY CODE ###

import copy
N = int(input())
capa = []
for i in range(5):
    capa.append(int(input()))

num_h = [N, 0, 0, 0, 0, 0]

i = 0
while num_h[5] < N:
    for j in range(5, 0, -1):
        if num_h[j-1] <= 0:
            continue
        if num_h[j-1] >= capa[j-1]:
            num_h[j-1] -= capa[j-1]
            num_h[j] += capa[j-1]
        else:
            num_h[j] += num_h[j-1]
            num_h[j-1] = 0
    i += 1

print(i)

### FIXED CODE ###

import math
N = int(input())
capa = []
for i in range(5):
    capa.append(int(input()))

num_h = [N, 0, 0, 0, 0, 0]
print(math.ceil(N / min(capa)) + 4)
### BUGGY CODE ###

N = int(input())
ans = 1
for i in range(1,N+1):
  ans *= i
print(ans % (10**9 +7))

### FIXED CODE ###

N = int(input())
ans = 1
for i in range(1,N+1):
  ans *= i
  if ans > 10**9 + 7:
    ans %= 10**9 + 7
print(ans)
### BUGGY CODE ###

a,b,n = map(int, input().split())
ans = 0
p = int(pow(n,0.5))
for x in range(n,p,-1):
    ans = max(int(a*x/b) - (a*int(x/b)),ans)
print(ans)

### FIXED CODE ###

a, b, n = map(int,input().split())
x = min(n,b-1)
print(int(a*(x%b) / b))
### BUGGY CODE ###

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
al = list(map(int, input().split()))
al_cnt = [0] * (n + 1)

for i in range(1, n + 1):
    al_cnt[i] = al.count(i)
max_cnt = 0

for j in range(1, n + 1):
    if al_cnt[j] >= 2:
        max_cnt += cmb(al_cnt[j], 2)

for l in range(n):
    if al_cnt[al[l]] >= 3:
        ans = max_cnt - cmb(al_cnt[al[l]], 2) + cmb(al_cnt[al[l]] - 1, 2)
        print(ans if ans > 0 else 0)
    else:
        ans = max_cnt - cmb(al_cnt[al[l]], 2)
        print(ans if ans > 0 else 0)


### FIXED CODE ###

from collections import Counter

n = int(input())
al = list(map(int, input().split()))
al_cnt = Counter(al)
ans = sum([i * (i - 1) // 2 for i in al_cnt.values()])
for j in al:
    print(ans - al_cnt[j] + 1)
### BUGGY CODE ###

N = int(input())
arr = list(map(int, input().split()))
puts = []

for i in range(1,N+1)[::-1]:
    if N//2 < i and arr[i-1] == 1:
        puts.append(i)
    else:
        c = len([p for p in puts if p % i == 0])
        if (c % 2 == 0 and arr[i-1] == 1) or (c % 2 == 1 and arr[i-1] == 0):
            puts.append(i)

print(len(puts))
if len(puts):
    print(" ".join(map(str, sorted(puts, reverse=True))))


### FIXED CODE ###

from collections import defaultdict
N = int(input())
arr = list(map(int, input().split()))
puts = []
dd = defaultdict(int)

def make_divisors(n):
    divisors = []
    # Nの最大の約数は√N
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

for i in range(1,N+1)[::-1]:
    if N//2 < i and arr[i-1] == 1:
        puts.append(i)
        ds = make_divisors(i)
        for j in ds:
            dd[j] += 1
    else:
        # c = len([p for p in puts if p % i == 0])
        c = dd[i]
        if (c % 2 == 0 and arr[i-1] == 1) or (c % 2 == 1 and arr[i-1] == 0):
            puts.append(i)
            ds = make_divisors(i)
            for j in ds:
                dd[j] += 1

print(len(puts))
if len(puts):
    print(" ".join(map(str, sorted(puts, reverse=True))))
### BUGGY CODE ###

N, M = [int(_) for _ in input().split()]
ab = [input().split() for _ in range(M)]

ab = sorted(ab)

for i in ab:
    if i[0] == "1":   
        for j in ab:
            if j[0] == i[1] and j[1] == str(N):
                print("POSSIBLE")
                exit()

print("IMPOSSIBLE")

### FIXED CODE ###

N, M = [int(_) for _ in input().split()]
ab = [input().split() for _ in range(M)]

goal = {i:0 for i in range(1, N+1)}
N = str(N)

ne = []
for i in ab:
    if i[0] == "1":
        goal[int(i[1])] = 1

for j in ab:
    if goal[int(j[0])] and j[1] == N:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")
### BUGGY CODE ###

from bisect import bisect_left

N = int(input())
l = []

for i in range(N):
    a = int(input())
    n = bisect_left(l,a)
    if n != 0:
        l[n-1] = a
    else:
        l = [a] + l
print(len(l))

### FIXED CODE ###

from bisect import bisect_left
from collections import deque
N = int(input())
d = deque()

for i in range(N):
    a = int(input())
    n = bisect_left(d, a)
    if n != 0:
        d[n-1] = a
    else:
        d.appendleft(a)
print(len(d))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
s=sorted(list(set(a)))
m=0
for i in s:
	m=max(m,a.count(i-1)+a.count(i)+a.count(i+1))
print(m)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
dic={}
for i in a:
	if i-1 in dic:
		dic[i-1]+=1
	else:
		dic[i-1]=1
	if i in dic:
		dic[i]+=1
	else:
		dic[i]=1
	if i+1 in dic:
		dic[i+1]+=1
	else:
		dic[i+1]=1
print(max(dic.values()))
### BUGGY CODE ###

def memfact(a,m):
    temp = 1
    yield temp
    for i in range(1,a+1):
        temp = temp * i % m
        yield temp
def comb(n,r,m):
    if r == 0: return 1
    return (memf[n]*pow(memf[r],m-2,m)*pow(memf[n-r],m-2,m)) % m


n,*a = map(int, open(0).read().split())
m = 1000000007
checker = set()
for i in range(n+1):
    if a[i] in checker:
        left = a.index(a[i])
        right = n - i
        break
    else:
        checker.add(a[i])
memf = []
mfappend = memf.append
for x in memfact(n+1,m):
    mfappend(x)
for i in range(1,n+2):
    ans = comb(n+1,i,m)
    for j in range(max(0,i-right-1),min(left,i-1)+1):
        ans = (ans-comb(left,j,m)*comb(right,i-j-1,m)) % m
    print(ans)

### FIXED CODE ###

def memfact(a,m):
    temp = 1
    yield temp
    for i in range(1,a+1):
        temp = temp * i % m
        yield temp
def comb(n,r,m):
    if r == 0: return 1
    return (memf[n]*pow(memf[r],m-2,m)*pow(memf[n-r],m-2,m)) % m


n,*a = map(int, open(0).read().split())
m = 1000000007
checker = set()
for i in range(n+1):
    if a[i] in checker:
        left = a.index(a[i])
        right = n - i
        break
    else:
        checker.add(a[i])
memf = []
mfappend = memf.append
for x in memfact(n+1,m):
    mfappend(x)
lr = left + right
for i in range(1,n+2):
    ans = comb(n+1,i,m)
    if i <= lr + 1:
        ans = (ans-comb(lr,i-1,m)) % m
    print(ans)
### BUGGY CODE ###

S = input('')
Q = int(input(''))
for i in range(Q):
    str = input('')
    if(str.count(' ') == 0 and str == '1'):
        S = S[::-1]
    else:
        if(str[0] == '2' and str[2] == '1'):
            S = '{0}{1}'.format(str[4], S)
        elif(str[0] == '2' and str[2] == '2'):
            S = '{0}{1}'.format(S, str[4])
print(S)

### FIXED CODE ###

S = input('')
Q = int(input(''))
head, tail, rev_flag = '', '', 1
for i in range(Q):
    char = input()
    if char == '1':
        rev_flag *= -1
    else:
        t, f, c = char.split()
        if (f == '1' and rev_flag == 1) or (f == '2' and rev_flag == -1):
            head = c + head
        elif (f == '2' and rev_flag == 1) or (f == '1' and rev_flag == -1):
            tail = tail + c
if rev_flag == 1:
    print(head, S, tail, sep='')
else:
    print(tail[::-1], S[::-1], head[::-1], sep='')
### BUGGY CODE ###

import fractions
import functools

MOD = 10**9 + 7

N = int(input())
A = [int(i) for i in input().split()]


def lcm(a, b):
    gcd = fractions.gcd(a, b)
    return (a * b) // gcd


LCM = functools.reduce(lcm, A)
ans = sum([(LCM // a) % MOD for a in A]) % MOD

print(ans)


### FIXED CODE ###

import functools
import fractions

MOD = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]

L = functools.reduce(lambda a, b: a // fractions.gcd(a, b) * b, A) % MOD
ans = 0

for a in A:
    ans += L * pow(a, MOD - 2, MOD)
    ans %= MOD

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

int_n = int(input())
list_x = list(map(int, input().split()))


list_calc_minus_2 = list()

#print([max(list_x[0:len(list_x)-i]) for i in range(len(list_x))])

for i in range(len(list_x)):
  list_calc_minus_2.insert(0, max(list_x[0:len(list_x)-i]))
  
#print(list_calc_minus_2)

print(sum([x - y for (x, y) in zip(list_calc_minus_2, list_x)]))


### FIXED CODE ###

int_n = int(input())
list_a = list(map(int, input().split()))

#print(int_n, list_a)

int_tmp_highet = 0
int_count = 0
for i in list_a:
  if i > int_tmp_highet:
    int_tmp_highet = i
  else:
    int_count = int_count + int_tmp_highet - i
  #print(int_count)

print(int_count)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

class Node:
    def __init__(self, n, N):
        self.id = n
        self.edges = []
        self.weights = [-1]*N
        self.color = 1
        self.s = 0
    def set_edge(self, e, w):
        self.edges.append(e)
        self.weights[e]=w
    def set_color(self, c_):
        self.color = c_
        self.s = 1

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):

    # init nodes
    nodes = [Node(i,N) for i in range(N)]
    # set edges
    for ui, vi, wi in zip(u, v, w):
        nodes[ui-1].set_edge(vi-1,wi)
        nodes[vi-1].set_edge(ui-1,wi)

    def cal(node):
        c_ = node.color
        for n in node.edges:
            if nodes[n].s == 0:
                if node.weights[n]%2==1:
                    nodes[n].set_color(c_*-1)
                else:
                    nodes[n].set_color(c_)                
                cal(nodes[n])
    
    cal(nodes[0])

    for n in nodes:
        print((n.color==1)*1)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):

    G=[dict() for i in range(N)]
    for i in range(N-1):
        ui,vi,wi=u[i],v[i],w[i]
        G[ui-1][vi-1]=wi
        G[vi-1][ui-1]=wi

    dist = [-1]*N
    p = [0]
    dist[0] = 0

    while (len(p)>0):
        k = p.pop()
        for n in G[k]:
            if dist[n]==-1:
                dist[n] = dist[k] + G[k][n]
                p.append(n)
    
    for x in dist:
        print(x%2)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

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

def cover(V, i):
    for j in range(i + 1, len(V)):
        if V[i] & V[j]:
            V[i] |=  V[j]
            del V[j]
            return True

n, m = map(int, raw_input().split())
V = []
for _ in range(m):
    v = set(map(int, raw_input().split()))
    V.append(v)

flag = True
while flag:
    flag = False
    for i in range(len(V)):
        if cover(V, i):
            flag = True
            break

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    flag = True
    for v in V:
        if s in v:
            if t in v:
                print "yes"
            else:
                print "no"
            flag = False
            break
    if flag:
        print "no"

### FIXED CODE ###

def bfs(i, c):
    global V, C

    q = [i]
    while len(q) > 0:
        j = q.pop()
        if C[j] == -1:
            C[j] = c
            q += V[j]

n, m = map(int, raw_input().split())
V = [[] for _ in range(n)]
C = [-1] * n
for _ in range(m):
    l, r = map(int, raw_input().split())
    V[l].append(r)
    V[r].append(l)

c = 0
for i in range(n):
    if C[i] == -1:
        bfs(i, c)
        c += 1

q = int(raw_input())
for _ in range(q):
    s, t = map(int, raw_input().split())
    if C[s] == C[t]:
        print "yes"
    else:
        print "no"
### BUGGY CODE ###

def func(li,b) :
    sum = 0
    for i in range(len(li)) :
        sum+= abs(li[i] - b - i - 1)
    return sum
def binary_search(li) :
    left = -1000000001
    right = 1000000001
    while right - left > 1 :
        med = (right + left) // 2
        x = func(li,med)
        mdx = func(li,med-1)
        pdx = func(li,med+1)
        if mdx > x and pdx < x :
            left = med
            continue
        elif mdx < x and pdx > x :
            right = med
            continue
        elif mdx >= x and pdx >= x :
            return x
    else :
        return -1
import sys
input = sys.stdin.readline
N = int(input())
A =[int(i) for i in input().split()]
print(binary_search(A))

### FIXED CODE ###

def func(li,b) :
    sum = 0
    for i in range(len(li)) :
        sum+= abs(li[i] - b - i - 1)
    return sum
def binary_search(li) :
    left = -1000000001
    right = 1000000001
    while right - left > 1 :
        med = (right + left) // 2
        x = func(li,med)
        mdx = func(li,med-1)
        pdx = func(li,med+1)
        if mdx > x and pdx < x :
            left = med
            continue
        elif mdx < x and pdx > x :
            right = med
            continue
        elif mdx >= x and pdx >= x :
            return x
    else :
        return -1
N = int(input())
A =[int(i) for i in input().split()]
print(binary_search(A))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())

graph=[set() for _ in range(N+1)]
for _ in range(M):
  A,B=map(int,input().split())
  graph[A].add(B)
#print(graph)

visited=[False]*(N+1)
def dfs(path):
  u=path[-1]
  visited[u]=True
  for v in graph[u]:
    if visited[v]:
      if path[0]==v:
        cycle_list.append(path+[v])
    else:
      dfs(path+[v])
  visited[u]=False

cycle_list=[]
for i in range(1,N+1):
  dfs([i])
  
#print(cycle_list)
for cycle in cycle_list:
  #print(cycle)
  cycle_set=set(cycle)
  for c in cycle:
    edge_subs=set()
    if len(cycle_set&graph[c])>1:
      break
  else:
    print(len(cycle)-1)
    for i in range(len(cycle)-1):
      print(cycle[i])
    break
else:
  print(-1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())

graph=[set() for _ in range(N+1)]
for _ in range(M):
  A,B=map(int,input().split())
  graph[A].add(B)
#print(graph)

visited=[False]*(N+1)
def dfs(path):
  global cycle
  u=path[-1]
  
  visited[u]=True  
  for v in graph[u]:
    if visited[v]:
      cycle=list(path+[v])
      return
    else:
      dfs(path+[v])      
    if cycle:
      return    
  visited[u]=False
  
cycle=[]
for i in range(1,N+1):
  dfs([i])
  if cycle:
    break
else:
  print(-1)
  sys.exit(0)
    
#remove prefix  
for i in range(len(cycle)):
  if cycle[i]==cycle[-1]:
    cycle=cycle[i:]
    break
#print(cycle)

cycle_set=set(cycle)
subgraph=[set() for _ in range(N+1)]
for c in cycle_set:
  for v in graph[c]:
    if v in cycle_set:
      subgraph[c].add(v)
#print(subgraph)    

#visited=[False]*(N+1)
ex_path=[]
def dfs2(path,t):
  global ex_path
  u=path[-1]
  if u==t:
    ex_path=path
    return
  
  for v in graph[u]:
    dfs2(path+[v],t)
    if ex_path:
      return

graph=subgraph
while True:
  for i in range(len(cycle)-1):
    u=cycle[i]
    v=cycle[i+1]
    w=-1
    if len(graph[u])>1:
      for x in graph[u]:
        if x!=v:
          w=x
          break
      break
  else:
    print(len(cycle)-1)
    for i in range(len(cycle)-1):
      print(cycle[i])
    sys.exit(0)
    
  #print(u,v,w)
  #w->u
  dfs2([w],u)
  cycle=ex_path+[w]
  #print(cycle)
  cycle_set=set(cycle)
  subgraph=[set() for _ in range(N+1)]
  for c in cycle_set:
    for v in graph[c]:
      if v in cycle_set:
        subgraph[c].add(v)
        
  graph=subgraph