from sys import setrecursionlimit

setrecursionlimit(10 ** 9)



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

A = [[int(i) for i in input().split()] for j in range(n + m - 1)]



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

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



for a, b in A:

    T[a].append(b)

    RT[b].add(a)



D = [0] * (n+1)

P = [0] * (n+1)

used = [0] * (n+1)



def dfs(p, i, depth):

    if used[i]:

        return None

    D[i] = depth

    P[i] = p

    used[i] = True

    for t in tuple(T[i]):

        RT[t].remove(i)

    for t in tuple(T[i]):

        if not RT[t]:

            dfs(i, t, depth+1)



def root(i):

    if not RT[i]:

        return i

    return root(tuple(RT[i])[0])



dfs(0, root(1), 1)

for p in P[1:]:

    print(p)
from sys import setrecursionlimit

setrecursionlimit(10 ** 9)



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

A = [[int(i) for i in input().split()] for j in range(n + m - 1)]



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

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

IN = [0] * (n+1)



for a, b in A:

    T[a].append(b)

    RT[b].append(a)

    IN[b] += 1



D = [0] * (n+1)

P = [0] * (n+1)

used = [0] * (n+1)



def dfs(p, i, depth):

    if used[i]:

        return None

    D[i] = depth

    P[i] = p

    used[i] = True

    for t in tuple(T[i]):

        IN[t] -= 1

    for t in tuple(T[i]):

        if IN[t] == 0:

            dfs(i, t, depth+1)



def root(i):

    if not RT[i]:

        return i

    return root(RT[i][0])



dfs(0, root(1), 1)

for p in P[1:]:

    print(p)
from sys import setrecursionlimit

setrecursionlimit(10**9)
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]
T = [[] for i in range(n + 1)]
RT = [set() for i in range(n + 1)]
for a, b in A:
    T[a].append(b)
    RT[b].add(a)
D = [0] * (n + 1)
P = [0] * (n + 1)
used = [0] * (n + 1)


def dfs(p, i, depth):
    if used[i]:
        return None
    D[i] = depth
    P[i] = p
    used[i] = True
    for t in tuple(T[i]):
        RT[t].remove(i)
    for t in tuple(T[i]):
        if not RT[t]:
            dfs(i, t, depth + 1)


def root(i):
    if not RT[i]:
        return i
    return root(tuple(RT[i])[0])


dfs(0, root(1), 1)
for p in P[1:]:
    print(p)

from sys import setrecursionlimit

setrecursionlimit(10**9)
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]
T = [[] for i in range(n + 1)]
RT = [[] for i in range(n + 1)]
IN = [0] * (n + 1)
for a, b in A:
    T[a].append(b)
    RT[b].append(a)
    IN[b] += 1
D = [0] * (n + 1)
P = [0] * (n + 1)
used = [0] * (n + 1)


def dfs(p, i, depth):
    if used[i]:
        return None
    D[i] = depth
    P[i] = p
    used[i] = True
    for t in tuple(T[i]):
        IN[t] -= 1
    for t in tuple(T[i]):
        if IN[t] == 0:
            dfs(i, t, depth + 1)


def root(i):
    if not RT[i]:
        return i
    return root(RT[i][0])


dfs(0, root(1), 1)
for p in P[1:]:
    print(p)

-RT = [set() for i in range(n + 1)] +RT = [[] for i in range(n + 1)] +IN = [0] * (n + 1) -    RT[b].add(a) +    RT[b].append(a) +    IN[b] += 1 -        RT[t].remove(i) +        IN[t] -= 1 -        if not RT[t]: +        if IN[t] == 0: -    return root(tuple(RT[i])[0]) +    return root(RT[i][0])