Harryxun/stf_run huggingface dataset:
import sys
h,w=map(int,input().split())
s=[]
for i in range(h):
  s.append(list(map(int,input().split())))
for i in range(h):
  for j in range(w-2):
    if s[i][j]=='.' and s[i][j+1]=='#' and s[i][j+2]=='.':
      if s[i][j+1]=='.':
        print('No')
        sys.exit()
    if s[i][0]=='#' and s[i][1]=='.':
      if s[min(h-1,i+1)][0]=='.':
        print('No')
        sys.exit()
    if s[i][w-2]=='.' and s[i][w-1]=='#':
      if s[min(h-1,i+1)][w-1]=='.':
        print('No')
        sys.exit()
print('Yes')
  

### FIXED CODE ###

h, w = map(int, input().split())

s = [input() for _ in range(h)]

ans = 'Yes'

for i in range(1, h-1):
    for j in range(1, w-1):
        if s[i][j] == '#' and s[i-1][j] == '.' and s[i+1][j] == '.' and s[i][j-1] == '.' and s[i][j+1] == '.':
            ans = 'No'

print(ans)
a,b=(int(x) for x in input().split())
 
import math 
 
i=0
while i<10001:
  i++
  if math.float(i)==a and math.float(i)==b:
    print(i)
    break
else:
  print(-1)

### FIXED CODE ###

S = input()
if S[0] == S[1] == S[2]:
  print('No')
else:
  print('Yes')
"""
At Coder :: Beginner Contest 178 :: D - Redistribution 
https://atcoder.jp/contests/abc178/tasks/abc178_d
"""


MOD = pow(10, 9) + 7


def solve(S):
    """Solve problem."""
    A = [1 for _ in range(S+1)]
    A[0] = A[1] = A[2] = 0
    for i in range(3, S+1):
        k = 3
        while i - k >= 0:
            A[i] = A[i-k] + A[i] % MOD
            k += 1
    return A[-1]


def main():
    """Main program."""
    import sys
    S = int(sys.stdin.readline())
    print(solve(S))


if __name__ == '__main__':
    main()


### FIXED CODE ###

"""
At Coder :: Beginner Contest 178 :: D - Redistribution 
https://atcoder.jp/contests/abc178/tasks/abc178_d
"""


MOD = pow(10, 9) + 7


def solve(S):
    """Solve problem."""
    if S < 3:
        return 0
    A = [1 for _ in range(S+1)]
    A[0] = A[1] = A[2] = 0
    for i in range(3, S+1):
        k = 3
        while i - k >= 0:
            A[i] = A[i-k] + A[i] % MOD
            k += 1
    return A[S]


def main():
    """Main program."""
    import sys
    S = int(sys.stdin.readline())
    print(solve(S))


if __name__ == '__main__':
    main()
# -*- coding: <encoding name> -*-

import math
a, b = map(int, input().split())
# range = d * 2 + 1
# c == 1 + a * n - n >= b
print(math.ceil((b - 1) / (a - 1))

### FIXED CODE ###

# -*- coding: <encoding name> -*-

import math
a, b = map(int, input().split())
# range = d * 2 + 1
# c == 1 + a * n - n >= b
print(math.ceil((b - 1) / (a - 1)))
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    sym1 = "#"
    sym2 = "."
    for i in range(h):
        if i%2 = 1:
		    sym1 = "#"
		    sym2 = "."
        else:
		    sym1 = "."
		    sym2 = "#"

        for j in range(w):
	        if j%2 == 1:
	            print(sym1,end="")
	        else:
	            print(sym2,end="")
	    print("")
    
    print("")

### FIXED CODE ###

while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i%2 == 1:
            sym1 = "#"
            sym2 = "."
        else:
            sym1 = "."
            sym2 = "#"

        for j in range(w):
            if j%2 == 1:
                print(sym1,end="")
            else:
                print(sym2,end="")
        print("")
    
    print("")
S=raw_input()
print S/3600:(s%3600)/60:s-(s%3600)/60

### FIXED CODE ###

S=input()
 
print str(S/3600)+':'+str((S%3600)/60)+':'+str(S%60)
n,m = map(int,input().split())
a = [map(int,input().split()) for i in range(m)]
b = sum(a)
if n-a<0:
  print('-1')
else:
  print(int(n-a))

### FIXED CODE ###

n,m = map(int,input().split())
try:
  a = list(map(int,input().split()))
  b = int(sum(a))
except EOFError:
  pass
if int(n-b)<0:
  print('-1')
else:
  print(int(n-b))
#! env/bin/local python3
# -*- coding:utf-8 -*-

is_first = False
while True:
    try:
        if is_first:
            n, m  = (int(i) for i in input().split())
            is_first = False
        else:
            arr = (int(i) for i in input().split())
    except EOFError:
        break

total_vote = sum(arr)
sorted_arr = sorted(arr)

list_up_arr = sorted_arr[-1: -m]

flag = False
for l in list_up_arr:
    if l >= 1 / (4 * m):
        flag = True

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

### FIXED CODE ###

#! env/bin/local python3
# -*- coding:utf-8 -*-

is_first = True
while True:
    try:
        if is_first:
            n, m  = [int(i) for i in input().split()]
            is_first = False
        else:
            arr = [int(i) for i in input().split()]
    except EOFError:
        break

total_vote = sum(arr)
sorted_arr = sorted(arr, reverse=True)

list_up_arr = sorted_arr[: m]

flag = True
for l in list_up_arr:
    if l < 1 / (4 * m) * total_vote:
        flag = False

print('Yes' if flag else 'No')
import numpy as np
import math
X,Y = map(int,input().split())
 
 
c1 = (2*Y-X)
if c1%3!=0:
  print(0)
 
else:
  def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
  
  c1 = c1//3
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = (x * (c3-i)) % mod
    y = (y * i) % mod
    
  result = (x * pow(y,mod-2,mod)) % mod
 
  print(result)

### FIXED CODE ###

r = int(input())

print(r**2)
import collections

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

even_num=[v[i] for i in range(0,n,2)]
odd_num=[v[i] for i in range(1,n,2)]

count_even=collections.Counter(even_num).most_common()
count_odd=collections.Counter(odd_num).most_common()

#count_even.append((0,0))
#count_odd.append((0,0))

if count_even[0][0] != count_odd[0][0]:
    print(n-count_even[0][1]-count_odd[0][1])
elif len(count_even)==1 and len(count_odd)==1:
    print(n//2)
elif len(count_even)==1:
    print(n-count_odd[1][1])
elif len(count_odd)==1:
    print(n-count_even[1][1])
else:
    odd_even=count_odd[0][1]+count_even[1][1]
    even_odd=count_even[0][1]+count_odd[1][1]
    if odd_even>even_odd:
        print(n-odd_num)
    else:
        print(n-even_odd)




### FIXED CODE ###

import collections

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

even_num=[v[i] for i in range(0,n,2)]
odd_num=[v[i] for i in range(1,n,2)]

count_even=collections.Counter(even_num).most_common()
count_odd=collections.Counter(odd_num).most_common()

#count_even.append((0,0))
#count_odd.append((0,0))

if count_even[0][0] != count_odd[0][0]:
    print(n-count_even[0][1]-count_odd[0][1])
elif len(count_even)==1 and len(count_odd)==1:
    print(n//2)
elif len(count_even)==1:
    print(n-count_odd[1][1])
elif len(count_odd)==1:
    print(n-count_even[1][1])
else:
    odd_even=count_odd[0][1]+count_even[1][1]
    even_odd=count_even[0][1]+count_odd[1][1]
    if odd_even>even_odd:
        print(n-odd_even)
    else:
        print(n-even_odd)
N = int(input())
A = map(int,input().split(" "))
m = int('-inf')
count = 0
for i in range(N-2,-1,-1):
  m = max(m,A[i+1])
  if A[i]>=m: count += 1
print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split(" ")))
m = float('-inf')
count = 1
for i in range(1,N):
    m = max(m,A[i-1])
    if A[i]>=m: count += 1
print(count)
color = input()
num = int(input())
if num >= 3200:
    print(color)
else:
    print('red')


### FIXED CODE ###

num = int(input())
color = input()
if num >= 3200:
    print(color)
else:
    print('red')
A, B = int(input())

if A - B*2 <= 0:
  print(0)
else:
  print(A - B*2)

### FIXED CODE ###

A, B = map(int, input().split())
C = A - B*2

if C >= 0:
  print(C)
else:
  print(0)
flag = 'No'
for i in range(2,10):
    if n % i == 0:
        if n // i < 10:
            flag = 'Yes'
            break
        else:
            continue
        
if n == 0:
    flag = 'No'

print(flag)

### FIXED CODE ###

n = int(input())

flag = 'No'
for i in range(1,10):
    if n % i == 0:
        if n // i < 10:
            flag = 'Yes'
            break
        else:
            continue

print(flag)
a, b, k = map(int, raw_input().split())
list = []
for i in range(a, b+1):
	list += [i]
list.sort()
if (b - a + 1)/2 > k:
	for i in range(0, k):
		print list[i]
	for i in range(b-a-k+1,b-a+1):
		print list[i]
else :
	for i in range(0, b-a+1):
		print list[i]

### FIXED CODE ###

a, b, k = map(int, raw_input().split())
if (b - a + 1)/2 >= k:
	for i in range(a, a + k):
		print i
	for i in range(b - k + 1,b + 1):
		print i
else :
	for i in range(a, b + 1):
		print i
a,b = map(int,input().split())

c = a*b
d = a*2 + b*2

print(c)print(d)

### FIXED CODE ###

a,b = [int(x) for x in input().split()]
print(a*b,(a+b)*2)
from math import ceil, floor

a, b = [int(c) for c in input()]
A = ceil(a / 0.08)
B = ceil(b/ 0.1)
 
if (A < B):
  if (floor(B * 0.08) == a):
    print(B)
  else:
    print(-1)
elif (B < A):
  if (floor(A*0.1) == b):
    print(A)
  else:
    print(-1)
else:
  print(-1);


### FIXED CODE ###

code = input()
if (len(set(list(code))) != 1):
  print("Yes")
else:
  print("No")
n=int(input())
a=[]
for i in range(0,n):
  a.append(input().split())
if 'Y' in a:
  print('Four')
else:
  print('Three')

### FIXED CODE ###

n=int(input())
a=input().split()
if 'Y' in a:
  print('Four')
else:
  print('Three')
a,b,c,d=map(int,input().split())
if (a+b)>(c+d):
  print('Left')
elif (a+b)==(c+d):
  print('Balanced')
else:
  pritn('Right')

### FIXED CODE ###

a,b,c,d=map(int,input().split())
if (a+b)>(c+d):
  print('Left')
elif (a+b)==(c+d):
  print('Balanced')
else:
  print('Right')
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, T = rl()
A = rl()
B = np.array(A)
answer = 1
profit = 0
for i in range(N):
    B = B[1:] 
    p = B.max() - A[i]
    if p > profit:
        profit = p
        answer = 1
    elif p == profit:
        answer += 1

print(answer)

# 40


### FIXED CODE ###

import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, T = rl()
A = rl()
answer = 1
profit = 0
min = A[0]
for i in range(1, N):
    if A[i] < min:
        min = A[i]
        continue
    x = A[i] - min
    if x > profit:
        answer = 1
        profit = x
    elif x == profit:
        answer += 1

print(answer)
# 40
import collections
def main():
    N, M = map(int, input().split())
    bridges = []
    for _ in range(M):
        a, b = map(int, input().split())
        bridges.append([a-1, b-1])
    bridges = bridges[::-1]
    parent = [i for i in range(N)]
    count = collections.defaultdict(int)
    for i in range(N): count[i] = 1

    def find(i):
        if parent[i] != i:
            parent[i] = find(parent[i])
        return parent[i]

    def union(i, j):
        pi, pj = find(i), find(j)
        df = 0
        if pi != pj:
            parent[pj] = pi
            df += count[pi] * count[pj]
            count[pi] += count[pj]
        return df

    ans = [N*(N-1)//2]
    for a, b in bridges:
        d = union(a, b)
        ans.append(ans[-1] - d)
    return ans[:-1][::-1]

if __name__ == '__main__':
    output = main()
    for v in output:
        print(v)

### FIXED CODE ###

import collections
def main():
    N, M = map(int, input().split())
    bridges = []
    for _ in range(M):
        a, b = map(int, input().split())
        bridges.append([a, b])
    bridges = bridges[::-1]
    parent = [i for i in range(N+1)]
    count = dict()
    for i in range(N+1): count[i] = 1

    def find(i):
        if parent[i] != i:
            parent[i] = find(parent[i])
        return parent[i]

    def union(i, j):
        pi, pj = find(i), find(j)
        df = 0
        if pi != pj:
            if count[pi] > count[pj]:
                parent[pj] = pi
                df += count[pi] * count[pj]
                count[pi] += count[pj]
                del count[pj]
            else:
                parent[pi] = pj
                df += count[pi] * count[pj]
                count[pj] += count[pi]
                del count[pi]                
        return df

    ans = [N*(N-1)//2]
    for a, b in bridges[:-1]:
        d = union(a, b)
        ans.append(ans[-1]-d)
    return ans[::-1]

if __name__ == '__main__':
    output = main()
    for v in output:
        print(v)
N=int(input())
n=[str(input()) for i in range(N)]
M=int(input())
m=[str(input()) for i in range(M)]
for i in range(N):
  print(max(0, max(n.count(n[i])-m.count(n[i]))))

### FIXED CODE ###

N=int(input())
n=[str(input()) for i in range(N)]
M=int(input())
m=[str(input()) for i in range(M)]
print(max(0, max(n.count(n[i])-m.count(n[i]) for i in range(N))))
n,q=map(int,input().split())
tree=[list(map(int,input().split())) for i in range(n-1)]
point=[list(map(int,input().split())) for i in range(q)]

ans=['?']+[0]*n

def dfs(x,y):
  ans[x]+=y
  for i in range(n-1):
    if tree[i][0]==x:
      dfs(tree[i][1],y)

for i,j in point:
  dfs(i,j)

ans2=''
for i in range(1,n+1):
  ans2+=str(ans[i])
  if i!=n:
    ans2+=' '

print(ans2)

### FIXED CODE ###

n,q=map(int,input().split())
lst=[[] for i in range(n)]
ans=[0]*n

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

for i in range(q):
    s,t=map(int,input().split())
    ans[s-1]+=t

Q=[0]

flag=[True]+[False]*(n-1)


while Q:
  v=Q.pop()
  flag[v]=True
  for i in lst[v]:
    if flag[i]:
      continue
    flag[i]=True
    ans[i]+=ans[v]
    Q.append(i)


print(' '.join([str(i) for i in ans]))
n,k=map(int,input().split())
s=list(input())
point=s[0]
count=0
while k!=0 and count!=n-1:
    if s[count]!=point:
        while True:
            if s[count]!=point:
                s[count]=point
                count +=1
            else:break
        k -=1
    else:count +=1

ans=0
for i in range(n-1,0,-1):
    if s[i]==s[i-1]:
        ans +=1
print(ans)

### FIXED CODE ###

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

s = input()

S = list(s)

num = 0
for i in range(N-1):

    if S[i] == S[i+1]:
        num += 1

print (min(N-1,num + 2*K))
N,W = map(int, input().split())


w=[0 for i in range(N)]
v=[0 for i in range(N)]

Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]

for i in range(N):
    w[i],v[i] = map(int, input().split())

for i in range(N):
    Wsum[i+1] = Wsum[i] + w[i+1]
    Vsum[i+1] = Vsum[i] + v[i+1]

w.insert(0,"0")
v.insert(0,"0")




Wmin = min(w)

nap_memo ={}

def nap(i,W2):
    kagi = str(i) + ':' +str(W2)
    if kagi in nap_memo:
        return nap_memo[kagi]
    elif i ==0:
        r=0
    elif W2<Wmin:
        r=0
    elif W2 < Wmin:
        r=0
    elif W2 < w[i]:
        r=nap(i-1,W2)
    elif Wsum[i]<=W2:
        r=Vsum[i]
    else:
        r=max( nap(i-1,W2-w[i])+v[i],nap(i-1,W2))
        
    nap_memo[kagi]=r
    return r

print(nap(N,W))
        
        
        
    

### FIXED CODE ###


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


w=[0 for i in range(N)]
v=[0 for i in range(N)]

Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]

for i in range(N):
    w[i],v[i] = map(int, input().split())
    


Wmin = min(w)    
w.insert(0,"0")
v.insert(0,"0")
for i in range(N):
    Wsum[i+1] = Wsum[i] + w[i+1]
    Vsum[i+1] = Vsum[i] + v[i+1]



nap_memo ={}

def nap(i,W2):
    kagi = str(i) + ':' +str(W2)
    if kagi in nap_memo:
        return nap_memo[kagi]
    elif i ==0:
        r=0
    elif W2<Wmin:
        r=0
    elif W2 < w[i]:
        r=nap(i-1,W2)
    elif Wsum[i]<=W2:
        r=Vsum[i]
    else:
        r=max( nap(i-1,W2-w[i])+v[i],nap(i-1,W2))
        
    nap_memo[kagi]=r
    return r

print(nap(N,W))
#sを最高のパターンにして，tを最悪のパターンにすればいい
#continueで強制的に次のループへ
s = list(input())
t = list(input())

s.sort()
t.sort()
t.reverse()

if len(s)  == len(t):
    pattern == -1
elif len(s) < len(t):
    length = len(s)
    pattern = 0
else:#sのほうが長い時 pattern = 1
    length = len(t)
    pattern = 1

if pattern == -1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] > t[i]:
            print("Yes")
            quit()
        else:
            print("No")
            quit()
elif pattern == 0:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] > t[i]:
            print("Yes")
            quit()
        else:
            print("No")
            quit()
    print("Yes")
elif pattern == 1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] > t[i]:
            print("Yes")
            quit()
        else:
            print("No")
            quit()
    print("No")
        
    



### FIXED CODE ###

#sを最高のパターンにして，tを最悪のパターンにすればいい
#continueで強制的に次のループへ
s = list(input())
t = list(input())
condition = 0

s.sort()
t.sort()
t.reverse()

if len(s)  == len(t):
    length = len(s)
    pattern = -1
elif len(s) < len(t):
    length = len(s)
    pattern = 0
else:#sのほうが長い時 pattern = 1
    length = len(t)
    pattern = 1

if pattern == -1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
    if condition == 0:
        print("No")
elif pattern == 0:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
    
    if condition == 0:
        print("Yes")
elif pattern == 1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
            
    if condition == 0:
        print("No")
def is_prime(x):
    if x==2:
        return 1
    elif x&1==0:
        return 0
    elif pow(2,x-1,x)==1:
        return 1
    else:
        return 0
N = int(input())
for i in range(N):
    n=int(input())
    c+=is_prime(n)
print(c)

### FIXED CODE ###

def is_prime(x):
    if x==2:
        return 1
    elif x&1==0:
        return 0
    else: return pow(2,x-1,x)==1
N = int(input())
c=0
for i in range(N):
    c+=is_prime(int(input()))
print(c)
import itertools

def findRoot(uf,value):
  if uf[value]==None:
    return value
  else:
    return findRoot(uf,uf[value])

n,m=[int(x) for x in input().split(' ')]

uf=[None]*n
b=[]
s=[1]*n
r=[]

for x in range(0,m):
  b.append([int(x)-1 for x in input().split(' ')])

for x in b[::-1]:
  r1=findRoot(uf,x[0])
  r2=findRoot(uf,x[1])

#経路圧縮
  if x[0]!=r1:
    uf[x[0]]=r1
  if x[1]!=r2:
    uf[x[1]]=r2

  if r1==r2:
    r.append(0)
  else:
    r.append(s[r1]*s[r2])
#木の結合
    uf[r2]=r1
    s[r1]+=s[r2]


for x in itertools.accumulate(r[::-1]):
  print(x)

### FIXED CODE ###

import itertools
import sys

def findRoot(uf,value):
  if uf[value]==None:
    return value
  else:
#経路圧縮
    uf[value]=findRoot(uf,uf[value])
    return uf[value]


sys.setrecursionlimit(50000)
n,m=[int(x) for x in input().split(' ')]

uf=[None]*n
b=[]
s=[1]*n
r=[]

for x in range(0,m):
  b.append([int(x)-1 for x in input().split(' ')])

for x in b[::-1]:
  r1=findRoot(uf,x[0])
  r2=findRoot(uf,x[1])

  if r1==r2:
    r.append(0)
  else:
    r.append(s[r1]*s[r2])
#木の結合
    uf[r2]=r1
    s[r1]+=s[r2]

for x in itertools.accumulate(r[::-1]):
  print(x)
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")-)
print(ans)

### FIXED CODE ###

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(ans)
import sys
input = sys.stdin.readline
def main():  
    S = list(input())
    length=len(S)
    dp = [[0]*13 for _ in range(length)]
    dp[0][0]=1
    mul=1
    for i in range(1,length):
        for j in range(13):
            if dp[i-1][j] != 0:
                if S[length-i-1] == "?":
                    for k in range(10):
                        dp[i][(j+k*mul)%13]+=dp[i-1][j]
                else: 
                    dp[i][(j+S[length-i-1]*mul)%13]+=dp[i-1][j]
        mul=mul*10
    print(dp[length-1][5]%1000000007, "d")
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():  
    S = list(input())
    S.pop()
    length=len(S)
    dp = [0]*13
    dp[0]=1
    mul=1
    mod=1000000007
    for i in range(1,length+1):
        next_dp = [0]*13
        for j in range(13):
            if S[length-i] == "?":
                for k in range(10):
                    j_sub=(j+k*mul)%13
                    next_dp[j_sub]+=dp[j]
                    next_dp[j_sub]%=mod
            else:
                j_sub=(j+int(S[length-i])*mul)%13
                next_dp[j_sub]+=dp[j]
                next_dp[j_sub]%=mod
        dp=next_dp
        mul=mul*10%13
    print(dp[5]%1000000007)
if __name__ == "__main__":
    main()
import sys

n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
root = set(range(n))
for line in sys.stdin.readlines():
    a, b = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add(b)
    root.discard(b)
root = root.pop()

parent = [-1] * n
depth = [-1] * n


def dfs(v, p, d):
    # print(v, p, d, parent, depth)
    if depth[v] != -1 and depth[v] > d:
        return
    parent[v] = p
    depth[v] = d
    for c in links[v]:
        dfs(c, v, d + 1)


dfs(root, -1, 0)

print('\n'.join(str(p + 1) for p in parent))


### FIXED CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10 ** 5 + 100)

n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
root = set(range(n))
for line in sys.stdin.readlines():
    a, b = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add(b)
    root.discard(b)
root = root.pop()

parents = [set() for _ in range(n)]
q = deque([(root, -1)])

while q:
    v, p = q.popleft()
    parents[v].add(p)
    if len(parents[v]) > 1:
        continue
    q.extend((c, v) for c in links[v])

fixed = [-1] * n

# print(parents)

q = deque([(root, -1)])
while q:
    v, p = q.popleft()
    pv = parents[v]
    pv.remove(p)
    if len(pv) == 0:
        fixed[v] = p
        q.extend((c, v) for c in links[v])

print('\n'.join(str(p + 1) for p in fixed))