from collections import deque



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

DAG = [[] for i in range(n)]

ins = [0]*n

ans = []

for i in range(n+m-1):

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

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

    ins[b-1] += 1

S = deque([])

for i in range(n):

    if ins[i] == 0:

        S.append([i,i])

while len(S) > 0:

    cur = S.popleft()

    ans.append(cur)

    for e in DAG[cur[0]]:

        ins[e] -= 1

        if ins[e] == 0:

            S.append([e,cur[0]])

ans.sort()

for i in range(n):

  if ans[i][0] == ans[i][1]:

    print((0))

  else:

    print((ans[i][1]+1))
from collections import deque



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

outs = [[] for i in range(n)]

ins = [0]*n

ans = []

for i in range(n+m-1):

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

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

    ins[b-1] += 1

S = deque([])

for i in range(n):

    if ins[i] == 0:

        S.append([i,i])

while len(S) > 0:

    cur = S.popleft()

    ans.append(cur)

    for e in outs[cur[0]]:

        ins[e] -= 1

        if ins[e] == 0:

            S.append([e,cur[0]])

ans.sort()

for i in range(n):

  if ans[i][0] == ans[i][1]:

    print((0))

  else:

    print((ans[i][1]+1))
from collections import deque

n, m = list(map(int, input().split()))
DAG = [[] for i in range(n)]
ins = [0] * n
ans = []
for i in range(n + m - 1):
    a, b = list(map(int, input().split()))
    DAG[a - 1].append(b - 1)
    ins[b - 1] += 1
S = deque([])
for i in range(n):
    if ins[i] == 0:
        S.append([i, i])
while len(S) > 0:
    cur = S.popleft()
    ans.append(cur)
    for e in DAG[cur[0]]:
        ins[e] -= 1
        if ins[e] == 0:
            S.append([e, cur[0]])
ans.sort()
for i in range(n):
    if ans[i][0] == ans[i][1]:
        print((0))
    else:
        print((ans[i][1] + 1))

from collections import deque

n, m = list(map(int, input().split()))
outs = [[] for i in range(n)]
ins = [0] * n
ans = []
for i in range(n + m - 1):
    a, b = list(map(int, input().split()))
    outs[a - 1].append(b - 1)
    ins[b - 1] += 1
S = deque([])
for i in range(n):
    if ins[i] == 0:
        S.append([i, i])
while len(S) > 0:
    cur = S.popleft()
    ans.append(cur)
    for e in outs[cur[0]]:
        ins[e] -= 1
        if ins[e] == 0:
            S.append([e, cur[0]])
ans.sort()
for i in range(n):
    if ans[i][0] == ans[i][1]:
        print((0))
    else:
        print((ans[i][1] + 1))

-DAG = [[] for i in range(n)] +outs = [[] for i in range(n)] -    DAG[a - 1].append(b - 1) +    outs[a - 1].append(b - 1) -    for e in DAG[cur[0]]: +    for e in outs[cur[0]]: