import sys

input = sys.stdin.readline

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

C = [list(map(int,input().split())) for i in range(n-1+m)]



r = -1

R = [1] * (n+1)

for i in range(len(C)):

    R[C[i][1]] = 0

for i in range(1, n+1):

    if R[i] == 1:

        r = i



# print(r)



F = [0] * (n+1)

P = [0] * (n+1)



M = [[] for i in range(n+1)]

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

    M[C[i][0]].append(C[i][1])

    F[C[i][1]] += 1



# 1始まりの場合

Q = [r]

s = 0

# V[r] = 1

while s < len(Q):

    i = Q[s]

    for x in M[i]:

        F[x] -= 1

        if F[x] == 0:

            P[x] = i

            Q.append(x)

    s += 1

# print(P)



for i in range(1, n+1):

    print((P[i]))
import sys

input = sys.stdin.readline

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

C = [list(map(int,input().split())) for i in range(n-1+m)]



r = -1

R = [1] * (n+1)

for i in range(len(C)):

    R[C[i][1]] = 0

for i in range(1, n+1):

    if R[i] == 1:

        r = i



# print(r)

IN = [0] * (n+1)

P = [0] * (n+1)



M = [[] for i in range(n+1)]

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

    M[C[i][0]].append(C[i][1])

    IN[C[i][1]] += 1



# INはその頂点を指している辺の本数のリスト



S = []

s = 0



for i in range(n):

    if IN[i] == 0:

        S.append(i)



while s < len(S):

    for x in M[S[s]]:

        IN[x] -= 1

        if IN[x] == 0:

            S.append(x)

    s += 1



for i in S:

    for j in M[i]:

        P[j] = i

for i in range(1, n+1):

    print((P[i]))
import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
C = [list(map(int, input().split())) for i in range(n - 1 + m)]
r = -1
R = [1] * (n + 1)
for i in range(len(C)):
    R[C[i][1]] = 0
for i in range(1, n + 1):
    if R[i] == 1:
        r = i
# print(r)
F = [0] * (n + 1)
P = [0] * (n + 1)
M = [[] for i in range(n + 1)]
for i in range(n - 1 + m):
    M[C[i][0]].append(C[i][1])
    F[C[i][1]] += 1
# 1始まりの場合
Q = [r]
s = 0
# V[r] = 1
while s < len(Q):
    i = Q[s]
    for x in M[i]:
        F[x] -= 1
        if F[x] == 0:
            P[x] = i
            Q.append(x)
    s += 1
# print(P)
for i in range(1, n + 1):
    print((P[i]))

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
C = [list(map(int, input().split())) for i in range(n - 1 + m)]
r = -1
R = [1] * (n + 1)
for i in range(len(C)):
    R[C[i][1]] = 0
for i in range(1, n + 1):
    if R[i] == 1:
        r = i
# print(r)
IN = [0] * (n + 1)
P = [0] * (n + 1)
M = [[] for i in range(n + 1)]
for i in range(n - 1 + m):
    M[C[i][0]].append(C[i][1])
    IN[C[i][1]] += 1
# INはその頂点を指している辺の本数のリスト
S = []
s = 0
for i in range(n):
    if IN[i] == 0:
        S.append(i)
while s < len(S):
    for x in M[S[s]]:
        IN[x] -= 1
        if IN[x] == 0:
            S.append(x)
    s += 1
for i in S:
    for j in M[i]:
        P[j] = i
for i in range(1, n + 1):
    print((P[i]))

-F = [0] * (n + 1) +IN = [0] * (n + 1) -    F[C[i][1]] += 1 -# 1始まりの場合 -Q = [r] +    IN[C[i][1]] += 1 +# INはその頂点を指している辺の本数のリスト +S = [] -# V[r] = 1 -while s < len(Q): -    i = Q[s] -    for x in M[i]: -        F[x] -= 1 -        if F[x] == 0: -            P[x] = i -            Q.append(x) +for i in range(n): +    if IN[i] == 0: +        S.append(i) +while s < len(S): +    for x in M[S[s]]: +        IN[x] -= 1 +        if IN[x] == 0: +            S.append(x) -# print(P) +for i in S: +    for j in M[i]: +        P[j] = i