from collections import deque



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

count = [0]*N

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

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



for i in range(N+M-1):

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

    side[a-1].append(b-1)

    rside[b-1].append(a-1)

    count[b-1] += 1

root = count.index(0)

queue = deque([root])

top = [0]*N



for i in range(N):

    q = queue.popleft()

    top[q] = i

    for k in side[q]:

        count[k] -= 1

        if count[k] == 0:

            queue.append(k)

for i in range(N):

    if rside[i] == []:

        print((0))

        continue

    ret = root

    for j in rside[i]:

        if top[ret] < top[j]:

            ret = j

    print((ret+1))

from collections import deque

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

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

counts = [0]*N

ans = [0]*N



for i in range(N+M-1):

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

    side[a-1].append(b-1)

    counts[b-1]+=1



queue = deque([counts.index(0)])

while queue:

    q = queue.popleft()

    for i in side[q]:

        counts[i] -= 1

        if counts[i] == 0:

            ans[i] = q+1

            queue.append(i)



for i in ans:

    print(i)
from collections import deque

N, M = list(map(int, input().split()))
count = [0] * N
side = [[] for i in range(N)]
rside = [[] for i in range(N)]
for i in range(N + M - 1):
    a, b = list(map(int, input().split()))
    side[a - 1].append(b - 1)
    rside[b - 1].append(a - 1)
    count[b - 1] += 1
root = count.index(0)
queue = deque([root])
top = [0] * N
for i in range(N):
    q = queue.popleft()
    top[q] = i
    for k in side[q]:
        count[k] -= 1
        if count[k] == 0:
            queue.append(k)
for i in range(N):
    if rside[i] == []:
        print((0))
        continue
    ret = root
    for j in rside[i]:
        if top[ret] < top[j]:
            ret = j
    print((ret + 1))

from collections import deque

N, M = list(map(int, input().split()))
side = [[] for _ in range(N)]
counts = [0] * N
ans = [0] * N
for i in range(N + M - 1):
    a, b = list(map(int, input().split()))
    side[a - 1].append(b - 1)
    counts[b - 1] += 1
queue = deque([counts.index(0)])
while queue:
    q = queue.popleft()
    for i in side[q]:
        counts[i] -= 1
        if counts[i] == 0:
            ans[i] = q + 1
            queue.append(i)
for i in ans:
    print(i)

-count = [0] * N -side = [[] for i in range(N)] -rside = [[] for i in range(N)] +side = [[] for _ in range(N)] +counts = [0] * N +ans = [0] * N -    rside[b - 1].append(a - 1) -    count[b - 1] += 1 -root = count.index(0) -queue = deque([root]) -top = [0] * N -for i in range(N): +    counts[b - 1] += 1 +queue = deque([counts.index(0)]) +while queue: -    top[q] = i -    for k in side[q]: -        count[k] -= 1 -        if count[k] == 0: -            queue.append(k) -for i in range(N): -    if rside[i] == []: -        print((0)) -        continue -    ret = root -    for j in rside[i]: -        if top[ret] < top[j]: -            ret = j -    print((ret + 1)) +    for i in side[q]: +        counts[i] -= 1 +        if counts[i] == 0: +            ans[i] = q + 1 +            queue.append(i) +for i in ans: +    print(i)