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

src = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(N-1+M)]

indeg_n = [0]*N

indeg = [[] for i in range(N)]

outdeg = [[] for i in range(N)]

for a,b in src:

    indeg_n[b] += 1

    indeg[b].append(a)

    outdeg[a].append(b)



root = indeg_n.index(0)

toposo = []

stack = [root]



while stack:

    v = stack.pop()

    toposo.append(v)

    for to in outdeg[v]:

        indeg_n[to] -= 1

        if indeg_n[to] == 0:

            stack.append(to)



order = [-1]*N

for i,v in enumerate(toposo):

    order[v] = i



ans = [-1]*N

ans[root] = 0

for ti in range(1,N):

    v = toposo[ti]

    maxo = max(order[p] for p in indeg[v])

    ans[v] = toposo[maxo] + 1

print(*ans, sep='\n')

import sys

input = sys.stdin.readline

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

AB = [tuple(map(int,input().split())) for i in range(N-1+M)]



es = [[] for _ in range(N)]

indeg = [0] * N

for a,b in AB:

    a,b = a-1,b-1

    es[a].append(b)

    indeg[b] += 1



from collections import deque

q = deque()

for i in range(N):

    if indeg[i] == 0:

        q.append(i)



ans = [0] * N

while q:

    v = q.popleft()

    for to in es[v]:

        indeg[to] -= 1

        if indeg[to] == 0:

            q.append(to)

            ans[to] = v+1

print(*ans, sep='\n')

N, M = map(int, input().split())
src = [tuple(map(lambda x: int(x) - 1, input().split())) for i in range(N - 1 + M)]
indeg_n = [0] * N
indeg = [[] for i in range(N)]
outdeg = [[] for i in range(N)]
for a, b in src:
    indeg_n[b] += 1
    indeg[b].append(a)
    outdeg[a].append(b)
root = indeg_n.index(0)
toposo = []
stack = [root]
while stack:
    v = stack.pop()
    toposo.append(v)
    for to in outdeg[v]:
        indeg_n[to] -= 1
        if indeg_n[to] == 0:
            stack.append(to)
order = [-1] * N
for i, v in enumerate(toposo):
    order[v] = i
ans = [-1] * N
ans[root] = 0
for ti in range(1, N):
    v = toposo[ti]
    maxo = max(order[p] for p in indeg[v])
    ans[v] = toposo[maxo] + 1
print(*ans, sep="\n")

import sys

input = sys.stdin.readline
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(N - 1 + M)]
es = [[] for _ in range(N)]
indeg = [0] * N
for a, b in AB:
    a, b = a - 1, b - 1
    es[a].append(b)
    indeg[b] += 1
from collections import deque

q = deque()
for i in range(N):
    if indeg[i] == 0:
        q.append(i)
ans = [0] * N
while q:
    v = q.popleft()
    for to in es[v]:
        indeg[to] -= 1
        if indeg[to] == 0:
            q.append(to)
            ans[to] = v + 1
print(*ans, sep="\n")

+import sys + +input = sys.stdin.readline -src = [tuple(map(lambda x: int(x) - 1, input().split())) for i in range(N - 1 + M)] -indeg_n = [0] * N -indeg = [[] for i in range(N)] -outdeg = [[] for i in range(N)] -for a, b in src: -    indeg_n[b] += 1 -    indeg[b].append(a) -    outdeg[a].append(b) -root = indeg_n.index(0) -toposo = [] -stack = [root] -while stack: -    v = stack.pop() -    toposo.append(v) -    for to in outdeg[v]: -        indeg_n[to] -= 1 -        if indeg_n[to] == 0: -            stack.append(to) -order = [-1] * N -for i, v in enumerate(toposo): -    order[v] = i -ans = [-1] * N -ans[root] = 0 -for ti in range(1, N): -    v = toposo[ti] -    maxo = max(order[p] for p in indeg[v]) -    ans[v] = toposo[maxo] + 1 +AB = [tuple(map(int, input().split())) for i in range(N - 1 + M)] +es = [[] for _ in range(N)] +indeg = [0] * N +for a, b in AB: +    a, b = a - 1, b - 1 +    es[a].append(b) +    indeg[b] += 1 +from collections import deque + +q = deque() +for i in range(N): +    if indeg[i] == 0: +        q.append(i) +ans = [0] * N +while q: +    v = q.popleft() +    for to in es[v]: +        indeg[to] -= 1 +        if indeg[to] == 0: +            q.append(to) +            ans[to] = v + 1