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

n = int(input())
C = []
MOD = 10 ** 9 + 7
pre = -1
for i in range(n):
    a = int(input())
    if a != pre:
        C.append(a)
    pre = a

N = len(C)
dp = [0] * (N + 1)
col = [[] for i in range(200005)]
pre = -1
dp[0] = 1
for i in range(1, N + 1):
    if len(col[C[i - 1]]) == 0:
        dp[i] = dp[i - 1]
        col[C[i - 1]].append(i)
    else:
        dp[i] = dp[i - 1]
        for j in col[C[i - 1]]:
            dp[i] += dp[j - 1]
            dp[i] %= MOD
        col[C[i - 1]].append(i)

print(dp[N])

### FIXED CODE ###

n = int(input())
C = []
MOD = 10 ** 9 + 7
pre = -1
for i in range(n):
    a = int(input())
    if a != pre:
        C.append(a)
    pre = a

N = len(C)
dp = [0] * (N + 1)
col = {}
pre = -1
dp[0] = 1
for i in range(1, N + 1):
    if C[i - 1] not in col:
        dp[i] = dp[i - 1]
        col[C[i - 1]] = dp[i]
    else:
        dp[i] = dp[i - 1]
        dp[i] += col[C[i - 1]]
        dp[i] %= MOD
        col[C[i - 1]] += dp[i - 1]

print(dp[N])
### BUGGY CODE ###

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

max_cnt = 0
for i in range(N-1):
    value = H[i]
    cnt = 0
    for j in range(i+1,N):
        if H[j] > value:
            break
        value = H[j]
        cnt += 1
    if cnt > max_cnt:
        max_cnt = cnt
    
print(max_cnt)

### FIXED CODE ###

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

max_cnt = 0
cnt_list = [0]
for i in range(N-2,-1,-1):
    value = H[i]
    cnt = 0
    cnt_list.append(cnt_list[-1]+1) if H[i] >= H[i+1] else cnt_list.append(0)
    #print(cnt_list)
print(max(cnt_list))
### BUGGY CODE ###


#かけて最小公倍数になる　そのために必要な数がB
from fractions import gcd
N=int(input())
if N==1:
  print(1)
  exit()

mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return (a*b)/gcd(a,b)

if N==2:
  LCM=lcm(A[0],A[1])
  ans=((LCM//A[0])+(LCM//A[1]))%mod
  print(ans)
  exit()

LCM=1
#LCM%=mod
for a in A:
  LCM=lcm(LCM, a)
  #LCM%=mod
  
#print(LCM)
ans=0
for a in A:
  ans+=LCM//a
  #ans%=mod

print(int(ans%mod))



### FIXED CODE ###


#かけて最小公倍数になる　そのために必要な数がB
from fractions import gcd
N=int(input())
if N==1:
  print(1)
  exit()

mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return a//gcd(a,b)*b

if N==2:
  LCM=lcm(A[0],A[1])
  ans=((LCM//A[0])+(LCM//A[1]))%mod
  print(ans)
  exit()

LCM=1
#LCM%=mod
for a in A:
  LCM=lcm(LCM, a)
  #LCM%=mod
  
#print(LCM)
ans=0
for a in A:
  ans+=LCM//a
  #ans%=mod

print(int(ans%mod))
### BUGGY CODE ###

N, Q = map(int, input().split())

S = [None] * N
T = [None] * N
X = [None] * N
for i in range(N):
    S[i], T[i], X[i] = map(int, input().split())

D = [None] * Q
for i in range(Q):
    D[i] = int(input())
    
    
# X S T
roadworks = [(x, s, t) for x, s, t in zip(X, S, T)]
roadworks = sorted(roadworks, reverse=True)
#print(roadworks)

# Dは入力時点でソート済み
walkers = D[:]
ans = [-1] * len(walkers)
import bisect
for x, s, t in roadworks:
    left = bisect.bisect_left(walkers, s - x)
    right = bisect.bisect_left(walkers, t - x)
    #print(left, right)
    for i in range(left, right):
        #print(i)
        ans[i] = x
    
#print(walkers)
for a in ans:
    print(a)
    




    
    


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, Q = map(int, input().split())

S = [None] * N
T = [None] * N
X = [None] * N
for i in range(N):
    S[i], T[i], X[i] = map(int, input().split())

D = [None] * Q
for i in range(Q):
    D[i] = int(input())
    
# X S T
roadworks = [(x, s, t) for x, s, t in zip(X, S, T)]
roadworks = sorted(roadworks, key=lambda x: x[0])
#print(roadworks)

# Dは入力時点でソート済み
walkers = D[:]
ans = [-1] * Q
skip = [-1] * Q

import bisect
for x, s, t in roadworks:
    left = bisect.bisect_left(walkers, s - x)
    right = bisect.bisect_left(walkers, t - x)
    
    i = left
    while i < right:
        if skip[i] == -1:
            ans[i] = x
            skip[i] = right
            i += 1
        else:
            i = skip[i]

    
#print(walkers)
for a in ans:
    print(a)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    s, l = map(int, input().split())
    temp = [l]*s
    upd.extend(temp)
upd.sort(reverse=True)

# output
f = len(a)
o = 0
c = len(upd)
ch = c
if f > c:
    for i in range(c):
        if upd[c-1-i] > a[c-1-i]:
            a[c-1-i] = upd[c-1-i]
        else:
            pass
else:
    for i in range(f):
        if upd[f-1-i] > a[f-1-i]:
            a[f-1-i] = upd[f-1-i]
        else:
            pass
print(sum(a))

### FIXED CODE ###

# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))
### BUGGY CODE ###

import sys,fractions
input = sys.stdin.readline

mod = 10**9+7
INF = float('inf')

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

lcm = 1
for a in lst_a:
    lcm = a*lcm//fractions.gcd(a,lcm)
ans = 0
for a in lst_a:
	ans += lcm*pow(a,mod-2,mod)
	ans %= mod
	
print(ans)


### FIXED CODE ###

import sys,fractions
input = sys.stdin.readline

mod = 10**9+7

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

lcm = 1
for a in lst_a:
    lcm = a*lcm//fractions.gcd(a,lcm)
lcm %= mod
ans = 0
for a in lst_a:
	ans += lcm*pow(a,mod-2,mod)
	ans %= mod

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

n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append([ipt[1]-1,ipt[2]])
    ar[ipt[1]-1].append([ipt[0]-1,ipt[2]])

ans = [[] for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
check = [False]*n #訪問済み
check[u] = True

while True:
    if len(queue) == 0:
        break
    u = queue.pop(0)
    for v in ar[u]:
        if not check[v[0]]:
            check[v[0]] = True
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])

for i in range(n):
    print(ans[i]%2)

### FIXED CODE ###

n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
N,M = map(int,input().split())
A = []
MOD = 10**9+7
memo = {}
for _ in range(M):
  A.append(int(input()))
def step(cur):
  if cur in memo:
    return memo[cur]
  if cur == N:
    memo[cur] = 1
    return memo[cur]
  if cur > N or cur in A:
    memo[cur] = 0
    return memo[cur]

  memo[cur] = (step(cur+1) + step(cur+2))%MOD
  return memo[cur]

print(step(0)%MOD)


### FIXED CODE ###

N,M = map(int,input().split())
MOD = 10**9+7
dp = [0] * (N+1)
dp[1] = 1
for _ in range(M):
  dp[int(input())] = -1
if N<2:
  print(dp[N])
  exit()

if dp[2] != -1:
  dp[2] = 1
for i in range(N+1):
  if dp[i] == -1: continue
  if i-1>=0 and dp[i-1] != -1:
    dp[i] += dp[i-1]
  if i-2>=0 and dp[i-2] != -1:
    dp[i] += dp[i-2]
  dp[i] %= MOD

print(dp[N])
### BUGGY CODE ###

n,w = (int(i) for i in input().split())
allItems = [[int(i) for i in input().split()] for j in range(n)]

allItems.sort(key = lambda x:x[0])
allItems.sort(key = lambda x:-x[1])

def getMaxSum(items,emptyWt):
    if emptyWt==0:
        return 0
    if emptyWt==1:
        for i in items:
            if i[0]==1:
                return i[1]
        return 0
    prevWt = {}
    maxRes = -1
    for i in range(len(items)):
        wt,val = items[i]
        if (wt in prevWt) or wt>emptyWt:
            continue
        prevWt[wt]=0
        res = val+getMaxSum(items[:i]+items[i+1:],emptyWt-wt)
        if res>maxRes:
            maxRes = res
    return maxRes
        
prevWt = {}
maxRes = -1
for i in range(n):
    wt,val = allItems[i]
    if wt in prevWt:
        continue
    prevWt[wt]=0
    res = val+getMaxSum(allItems[:i]+allItems[i+1:],w-wt)
    if res>maxRes:
        maxRes = res
print(maxRes)


### FIXED CODE ###

import numpy as np

n,W = (int(i) for i in input().split())
weights = []
values = []
for j in range(n):
    wt, val = [int(i) for i in input().split()]
    weights.append(wt)
    values.append(val)

dp  = np.zeros(W+1)

for i in range(1,n+1):
    w = weights[i-1]
    v = values[i-1]
    dp[w:] = np.maximum(dp[w:],v+dp[:-w])

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

# E - Two Currencies

import heapq

n, m, s = map(int, input().split())
adj = {u: [] for u in range(1, n+1)}
for i in range(m):
    u, v, a, b = map(int, input().split())
    adj[u].append((v, a, b)) # to, 料金, 時間
    adj[v].append((u, a, b)) # to, 料金, 時間
exch = {}
for u in range(1, n+1):
    c, d = map(int, input().split())
    exch[u] = (c, d) # レート, 時間

max_silver = 50 * m    # これだけ持ってたらどの都市へも行ける
s = min(s, max_silver) # max_silverまでで十分

# n <= 50, m <= 100, max_silver <= 5000

# (都市,所有銀貨)を頂点とする最短経路問題
# Dijkstra
dist = {(1, s): 0}  # 開始頂点のみ距離0
queue = [(0, 1, s)]
dmin = {1: 0} # dmin[u] = min(dist[(u, si)] for si)
nfin = 1      # 距離が決まった都市数

while len(queue) > 0:
    di, u, si = heapq.heappop(queue)
    # 用済みのデータ
    if (u, si) in dist and di > dist[(u, si)]:
        continue
    # 都市uの距離を保存
    if u not in dmin:
        dmin[u] = di
        nfin += 1
        if nfin >= n:  # 全都市の距離が決まった
            break
    # uから直接行ける各都市について
    for v, a, b in adj[u]:
        if si < a:  # 銀貨不足
            continue
        xsi = si - a
        if (v, xsi) not in dist or \
            dist[(v, xsi)] > di + b:
            dist[(v, xsi)] = di + b
            heapq.heappush(queue, (di + b, v, xsi))
    # 両替による遷移
    c, d = exch[u]
    xsi = min(si + c, max_silver)
    if (u, xsi) not in dist or \
        dist[(u, xsi)] > di + d:
        dist[(u, xsi)] = di + d
        heapq.heappush(queue, (di + d, u, xsi))

for u in range(2, n+1):
    print(dmin[u])


### FIXED CODE ###

# E - Two Currencies

import heapq

n, m, s = map(int, input().split())
adj = {u: [] for u in range(1, n+1)}
max_silver = 0
for i in range(m):
    u, v, a, b = map(int, input().split())
    adj[u].append((v, a, b)) # to, 料金, 時間
    adj[v].append((u, a, b)) # to, 料金, 時間
    max_silver += a # 全路線の料金の総和 (これ以上は不要)
exch = {}
for u in range(1, n+1):
    c, d = map(int, input().split())
    exch[u] = (c, d) # レート, 時間

s = min(s, max_silver) # max_silverまでで十分

# n <= 50, m <= 100, max_silver <= 5000

# (都市,所有銀貨)を頂点とする最短経路問題
# Dijkstra
dist = {(1, s): 0}  # 開始頂点のみ距離0
queue = [(0, 1, s)]
dmin = {1: 0} # dmin[u] = min(dist[(u, si)] for si)
nfin = 1      # 距離が決まった都市数

while len(queue) > 0:
    di, u, si = heapq.heappop(queue)
    # 用済みのデータ
    if (u, si) in dist and di > dist[(u, si)]:
        continue
    # 都市uの距離を保存
    if u not in dmin:
        dmin[u] = di
        nfin += 1
        if nfin >= n:  # 全都市の距離が決まった
            break
    # uから直接行ける各都市について
    for v, a, b in adj[u]:
        if si < a:  # 銀貨不足
            continue
        xsi = si - a
        if (v, xsi) not in dist or \
            dist[(v, xsi)] > di + b:
            dist[(v, xsi)] = di + b
            heapq.heappush(queue, (di + b, v, xsi))
    # 両替による遷移
    c, d = exch[u]
    xsi = min(si + c, max_silver)
    if (u, xsi) not in dist or \
        dist[(u, xsi)] > di + d:
        dist[(u, xsi)] = di + d
        heapq.heappush(queue, (di + d, u, xsi))

for u in range(2, n+1):
    print(dmin[u])
### BUGGY CODE ###



def submit():
    n = int(input())
    a = (int(e) for e in input().split())
    thr = 10 ** 18

    ans = 1
    for e in a:
        ans *= e
    
    if ans > thr:
        print(-1)
    else:
        print(ans)


submit()
        

### FIXED CODE ###


def submit():
    n = int(input())
    a = [int(e) for e in input().split()]
    thr = 10 ** 18

    if 0 in a:
        print(0)
        return

    ans = 1
    for e in a:
        ans *= e
        if ans > thr:
            ans = -1
            break
    
    print(ans)


submit()
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if j - i == a[j] + a[i]:
            ans +=1
print(ans)

### FIXED CODE ###

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

H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]

dp = [0] * (H+1)

for i in range(1, 1+H):
  dp[i] = 10 ** 8
  for A, B in AB:
    if i >= A:
      t = dp[i - A] + B
      if t < dp[i]:
        dp[i] = t
    else:
      if B < dp[i]:
        dp[i] = B

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


### FIXED CODE ###

H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]

dp = [0] * (H+1)

for i in range(1, 1+H):
  dp[i] = 10 ** 8
  for A, B in AB:
    if i >= A:
      t = dp[i - A] + B
      if t < dp[i]:
        dp[i] = t
    else:
      if B < dp[i]:
        dp[i] = B

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

N = int(input())
A = []
for i in range(N):
  A.append(int(input())-1)
    
ans = -1
push = 0
count = []

for i in range(N+1):

    if A[push] == 1:
        ans = i+1
        break
        
    elif A[push] in count:
      break
      
    else:
        push = A[push]
        count.append(push)
      
print(ans)

### FIXED CODE ###

n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)
### BUGGY CODE ###

c = [list(map(int, input().split())) for _ in range(3)]
ok = False
for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1 = c[0][0] - a1
            b2 = c[0][1] - a1
            b3 = c[0][2] - a1
            a = [a1, a2, a3]
            b = [b1, b2, b3]
            ok_sub = True
            for i in range(3):
                for j in range(3):
                    if a[i] + b[j] != c[i][j]:
                        ok_sub = False
            if ok_sub:
                ok = True

print('Yes') if ok else print('No')

### FIXED CODE ###

c = [list(map(int, input().split())) for _ in range(3)]
ok = False
for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1 = c[0][0] - a1
            b2 = c[0][1] - a1
            b3 = c[0][2] - a1

            a = [a1, a2, a3]
            b = [b1, b2, b3]
            ok_sub = True
            for i in range(3):
                for j in range(3):
                    if a[i] + b[j] != c[i][j]:
                        ok_sub = False
            if ok_sub:
                ok = True

print('Yes') if ok else print('No')
### BUGGY CODE ###

import collections

q = int(input())
a = [input() for _ in range(q)]

dic = collections.Counter(a)

keys = [k for k, v in dic.items() if v == max(dic.values())]
keys_s = sorted(keys)
for i in keys_s:
    print(i)
    

### FIXED CODE ###

import collections
import sys
input = sys.stdin.readline

q = int(input())
a = [input().rstrip() for _ in range(q)]

dic = collections.Counter(a)

ma = max(dic.values())
keys = [k for k, v in dic.items() if v == ma]
keys_s = sorted(keys)
for i in keys_s:
    print(i)
### BUGGY CODE ###

from collections import deque
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
#print(a)
#黒のマスを探索する
#黒のマスの周囲四マスを黒に変更する
#探索済みのところはTrueにする
log=[[-1]*W for i in range(H)]
def bfs():
    task=deque([])
    #初め黒のマスを検索する
    for i in range(H):
        for j in range(W):
            if a[i][j]=='#':
                task.append((i,j))
                log[i][j]=0

    dh=[0,1,0,-1]
    dw=[1,0,-1,0]

    while task:
        h,w=task.popleft()
        #四マスを探索する
        for i in range(4):
            nh=h+dh[i]
            nw=w+dw[i]
            if not(0<=nh<H and 0<=nw<W):continue
            if a[nh][nw]=='#':continue
            a[nh][nw]='#'
            log[nh][nw]=log[h][w]+1
            task.append((nh,nw))

def ans_check():
    ans=0
    for i in range(H):
        for j in range(W):
            if ans<log[i][j]:ans=log[i][j]

    print(ans)

bfs()
ans_check()


### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
#print(a)
#黒のマスを探索する
#黒のマスの周囲四マスを黒に変更する
#探索済みのところはTrueにする
log=[[-1]*W for i in range(H)]
def bfs():
    task=deque([])
    #初め黒のマスを検索する
    for i in range(H):
        for j in range(W):
            if a[i][j]=='#':
                task.append((i,j))
                log[i][j]=0

    dh=[0,1,0,-1]
    dw=[1,0,-1,0]

    while task:
        h,w=task.popleft()
        #四マスを探索する
        for i in range(4):
            nh=h+dh[i]
            nw=w+dw[i]
            if not(0<=nh<H and 0<=nw<W):continue
            if a[nh][nw]=='#':continue
            a[nh][nw]='#'
            log[nh][nw]=log[h][w]+1
            task.append((nh,nw))

def ans_check():
    ans=0
    for i in range(H):
        for j in range(W):
            if ans<log[i][j]:ans=log[i][j]

    print(ans)

bfs()
ans_check()
### BUGGY CODE ###

import collections

N=int(input())
A=[int(_) for _ in input().split(" ")]
Q=int(input())

c = collections.Counter(A)


#d['k10'] = d.pop('k1')    
    
for i in range(Q):
  B,C=map(int,input().split(" "))
  
  if C in c:
    c[C] += c[B]
    del c[B]
  else:
    c[C] = c[B]
    del c[B]
  
  #print(c)
  
  #s=list(c.keys())
  ans=0
  for v in c:
    ans += v*c[v]
  
  print(ans)

### FIXED CODE ###

import collections

N=int(input())
A=[int(_) for _ in input().split(" ")]
Q=int(input())

c = collections.Counter(A)

ans=0
for v in c:
  ans += v*c[v]

#print(c)
#d['k10'] = d.pop('k1')    
    
for i in range(Q):
  B,C=map(int,input().split(" "))
  
  if C in c:
    ans=ans-B*c[B]+C*c[B]
    c[C] += c[B]
    del c[B]
  else:
    ans=ans-B*c[B]+C*c[B]
    c[C] = c[B]
    del c[B]
  
  print(ans)
### BUGGY CODE ###

def b(n): # n次元バーガー
    if n == 0:
        return "P "
    else:
        return "B " + b(n-1) + "P " + b(n-1) + "B "
n, x= map(int, input().split())
print(b(n).split(" ", x).count("P"))

### FIXED CODE ###

def m(n): # n次元バーガーの層数
    if n == 0:
        return 1
    else:
        a = 1
        for i in range(n):
            a = a * 2 + 3
        return a

def paty(n): # n次元バーガーのパティの数
    a = 1
    if n >= 1:
        for i in range(n):
            a = a * 2 + 1
    return a

def a(n, x): #これが答えを返す
    x = x - 1
    if x == 0 and n == 0:
        return 1
    elif x == 0:
        return 0
    elif x == m(n-1) + 1:
        return paty(n-1) + 1
    elif x == m(n):
        return paty(n)
    elif x > m(n-1):
        return paty(n-1) + 1 + a(n - 1, x - m(n-1) - 1)
    else:
        n = n - 1
        return a(n, x)

n, x= map(int, input().split())
print(a(n, x))
### BUGGY CODE ###

s=str(input())
c=len(s)

for _ in range(10000):
        s=s.replace('01','')
        s=s.replace('10','')
        d=s.count('01')
        e=s.count('10')
        if d==0 and e==0:
                break
print(c-len(s))

### FIXED CODE ###

s=str(input())

a=s.count('0')
b=s.count('1')
print(min(a,b)*2)
### BUGGY CODE ###

import collections

n = int(input())
combination_count = 0
s = []
for _ in range(n):
    si = collections.Counter(input())
    combination_count += sum(1 for old_si in s if old_si == si)
    s.append(si)

print(combination_count)


### FIXED CODE ###

import collections

n = int(input())
counter = collections.Counter(str(sorted(input())) for _ in range(n))
combination_count = sum((v - 1) * v // 2 for v in counter.values())

print(combination_count)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
N,M=map(int,input().split())
from collections import defaultdict
OUT=defaultdict(set)
IN=defaultdict(set)
start={i for i in range(N)}
for i in range(N+M-1):
    a,b=map(int,input().split())
    start-={b-1}
    OUT[a-1]|={(i,b-1)}
    IN[b-1]|={i}
P=[0]*N
while len(start)>0:
    now=start.pop()
    for b,nex in OUT[now]:
        if len(IN[nex])==1:
            start|={nex}
            P[nex]=now+1
        IN[nex]-={b}
for p in P:
    print(p)

### FIXED CODE ###

import sys
input=sys.stdin.readline
N,M=map(int,input().split())
from collections import defaultdict
OUT=defaultdict(set)
IN=defaultdict(int)
for i in range(N+M-1):
    a,b=map(int,input().split())
    OUT[a-1]|={b-1}
    IN[b-1]+=1
P=[0]*N
start={i for i in range(N) if IN[i]==0}
while len(start)>0:
    now=start.pop()
    for nex in OUT[now]:
        IN[nex]-=1
        if IN[nex]==0:
            start|={nex}
            P[nex]=now+1
[print(p) for p in P]
### BUGGY CODE ###

A, B, C, D = map(int, input().split())
ans = set()
for i in range(A,B+1):
    if i % C != 0 and i % D != 0:
        ans.add(i)
    else:
        pass

print(len(ans))

### FIXED CODE ###

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(x, y):
    return (x * y) // gcd(x, y)


A, B, C, D = map(int, input().split())
ans = set()
if A%C == 0:
    c = (B//C) - (A//C) + 1
else:
    c = (B//C) - (A//C)

if A%D == 0:
    d = (B//D) - (A//D) + 1
else:
    d = (B//D) - (A//D)

CD = lcm(C, D)

if A%CD == 0:
    cd = (B//CD) - (A//CD) + 1
else:
    cd = (B//CD) - (A//CD)

print(B - A + 1 - (c+d-cd))
### BUGGY CODE ###

n = int(input())

ans = 1
flag = True
a = list(map(int, input().split()))
for i in a:
    ans *= i
    if ans > 1000000000000000000:
        flag = False

if ans == 0:
    flag = True

if flag:
    print(ans)
else:
    print(-1)


### FIXED CODE ###

n = int(input())

ans = 1
flag = True
a = list(map(int, input().split()))

a.sort()

if a[0] == 0:
    print(0)
    exit(0)

for i in a:
    ans *= i
    if ans > 10 ** 18:
        print(-1)
        exit(0)

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

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

N, K = map(int, input().split())
xi = list(map(int, input().split()))

kouho = []
ans_list = []
for i in range(N-K+1):
    li = xi[i:i+K]
    if li[0]*li[-1] < 0:
        ans_list.append(abs(li[0])*2 + abs(li[-1]))
        ans_list.append(abs(li[-1])*2 + abs(li[0]))
    elif li[0] < 0:
        ans_list.append(abs(li[0]))
    else: #if li[-1] > 0:
        ans_list.append(abs(li[-1]))

print(min(ans_list))


### FIXED CODE ###

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

N, K = map(int, input().split())
xi = list(map(int, input().split()))

ans_list = []
for i in range(N-K+1):
    l = xi[i]
    r = xi[i+K-1]
    if l*r < 0:
        a = abs(l)*2 + abs(r)
        b = abs(r)*2 + abs(l)
        if a > b :
            ans_list.append(b)
        else:
            ans_list.append(a)
    elif l < 0:
        ans_list.append(abs(l))
    else: #if li[-1] > 0:
        ans_list.append(abs(r))

print(min(ans_list))