import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools

N, M = [int(_) for _ in input().split()]

AB = [[int(_) for _ in input().split()] for _ in range(N - 1 + M)]



G = [set() for _ in range(N + 1)]

count = [0] * (N + 1)

ans = [0] * (N + 1)

for a, b in AB:

    G[a].add(b)

    count[b] += 1

for i in range(1, N):

    if count[i] == 0:

        root = collections.deque([i])

        break

while root:

    p = root.popleft()

    for c in G[p]:

        count[c] -= 1

        if count[c] == 0:

            ans[c] = p

            root.append(c)

print(*ans[1:], sep='\n')

import collections

N, M, *AB = [int(_) for _ in open(0).read().split()]

parent_children = collections.defaultdict(set)

child_parents = collections.defaultdict(set)

for a, b in zip(AB[::2], AB[1::2]):

    parent_children[a].add(b)

    child_parents[b].add(a)

root = (set(range(1, N + 1)) - set(child_parents.keys())).pop()





def bfs(root):

    Q = collections.deque([root])

    while Q:

        cur = Q.pop()

        for to in parent_children[cur]:

            if len(child_parents[to]) > 1:

                child_parents[to].remove(cur)

            else:

                Q += [to]





bfs(root)

child_parents[root] = {0}

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

    print((child_parents[i].pop()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools

N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N - 1 + M)]
G = [set() for _ in range(N + 1)]
count = [0] * (N + 1)
ans = [0] * (N + 1)
for a, b in AB:
    G[a].add(b)
    count[b] += 1
for i in range(1, N):
    if count[i] == 0:
        root = collections.deque([i])
        break
while root:
    p = root.popleft()
    for c in G[p]:
        count[c] -= 1
        if count[c] == 0:
            ans[c] = p
            root.append(c)
print(*ans[1:], sep="\n")

import collections

N, M, *AB = [int(_) for _ in open(0).read().split()]
parent_children = collections.defaultdict(set)
child_parents = collections.defaultdict(set)
for a, b in zip(AB[::2], AB[1::2]):
    parent_children[a].add(b)
    child_parents[b].add(a)
root = (set(range(1, N + 1)) - set(child_parents.keys())).pop()


def bfs(root):
    Q = collections.deque([root])
    while Q:
        cur = Q.pop()
        for to in parent_children[cur]:
            if len(child_parents[to]) > 1:
                child_parents[to].remove(cur)
            else:
                Q += [to]


bfs(root)
child_parents[root] = {0}
for i in range(1, N + 1):
    print((child_parents[i].pop()))

-import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools +import collections -N, M = [int(_) for _ in input().split()] -AB = [[int(_) for _ in input().split()] for _ in range(N - 1 + M)] -G = [set() for _ in range(N + 1)] -count = [0] * (N + 1) -ans = [0] * (N + 1) -for a, b in AB: -    G[a].add(b) -    count[b] += 1 -for i in range(1, N): -    if count[i] == 0: -        root = collections.deque([i]) -        break -while root: -    p = root.popleft() -    for c in G[p]: -        count[c] -= 1 -        if count[c] == 0: -            ans[c] = p -            root.append(c) -print(*ans[1:], sep="\n") +N, M, *AB = [int(_) for _ in open(0).read().split()] +parent_children = collections.defaultdict(set) +child_parents = collections.defaultdict(set) +for a, b in zip(AB[::2], AB[1::2]): +    parent_children[a].add(b) +    child_parents[b].add(a) +root = (set(range(1, N + 1)) - set(child_parents.keys())).pop() + + +def bfs(root): +    Q = collections.deque([root]) +    while Q: +        cur = Q.pop() +        for to in parent_children[cur]: +            if len(child_parents[to]) > 1: +                child_parents[to].remove(cur) +            else: +                Q += [to] + + +bfs(root) +child_parents[root] = {0} +for i in range(1, N + 1): +    print((child_parents[i].pop()))