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



P = [0] * (n+1)

used = [0] * (n+1)



def dfs(p, i):

    if used[i]:

        return None

    P[i] = p

    used[i] = True

    for t in T[i]:

        IN[t] -= 1

    for t in T[i]:

        if IN[t] == 0:

            dfs(i, t)



def root(i):

    if not RT[i]:

        return i

    return root(RT[i][0])



dfs(0, root(1))

for p in P[1:]:

    print(p)
from sys import setrecursionlimit

setrecursionlimit(10 ** 9)

from collections import deque



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



P = [0] * (n+1)



def bfs(v):

    q = deque()

    q.append(v)

    P[v] = 0

    while q:

        v = q.pop()

        for t in T[v]:

            IN[t] -= 1

            if IN[t] == 0:

                P[t] = v

                q.append(t)



def root(i):

    if not RT[i]:

        return i

    return root(RT[i][0])



bfs(root(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
P = [0] * (n + 1)
used = [0] * (n + 1)


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


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


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

from sys import setrecursionlimit

setrecursionlimit(10**9)
from collections import deque

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
P = [0] * (n + 1)


def bfs(v):
    q = deque()
    q.append(v)
    P[v] = 0
    while q:
        v = q.pop()
        for t in T[v]:
            IN[t] -= 1
            if IN[t] == 0:
                P[t] = v
                q.append(t)


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


bfs(root(1))
for p in P[1:]:
    print(p)

+from collections import deque + -used = [0] * (n + 1) -def dfs(p, i): -    if used[i]: -        return None -    P[i] = p -    used[i] = True -    for t in T[i]: -        IN[t] -= 1 -    for t in T[i]: -        if IN[t] == 0: -            dfs(i, t) +def bfs(v): +    q = deque() +    q.append(v) +    P[v] = 0 +    while q: +        v = q.pop() +        for t in T[v]: +            IN[t] -= 1 +            if IN[t] == 0: +                P[t] = v +                q.append(t) -dfs(0, root(1)) +bfs(root(1))