import sys

sys.setrecursionlimit(10 ** 9)



N, M = list(map(int, input().split()))

G = [[] for i in range(N)]

for i in range(N - 1 + M):

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

    a, b = a - 1, b - 1

    G[a].append(b)





def topological_sort(g):

    topological_list = []

    visited = set()



    def dfs(n):

        for e in g[n]:

            if e not in visited:

                dfs(e)

        topological_list.append(n)

        visited.add(n)



    for i in range(len(g)):

        if i not in visited:

            dfs(i)



    return topological_list[::-1]





topological_order = topological_sort(G)





# 根からの最長経路を計算

dist = [-float('inf')] * N

dist[topological_order[0]] = 0

for n in topological_order:

    for to in G[n]:

        dist[to] = max(dist[to], dist[n] + 1)





node_depth = sorted(list(enumerate(dist)), key=lambda x: x[1])

ans = [[node_depth[0][0], -1]]

for n, depth in node_depth:

    for to in G[n]:

        if dist[to] == depth + 1:

            ans.append([to, n])



ans.sort()

for i, p in ans:

    print((p + 1))

import sys

sys.setrecursionlimit(10 ** 9)



N, M = list(map(int, input().split()))

G = [[] for i in range(N)]

for i in range(N - 1 + M):

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

    a, b = a - 1, b - 1

    G[a].append(b)





def topological_sort(g):

    topological_list = []

    visited = set()



    def dfs(n):

        for e in g[n]:

            if e not in visited:

                dfs(e)

        topological_list.append(n)

        visited.add(n)



    for i in range(len(g)):

        if i not in visited:

            dfs(i)



    return topological_list[::-1]





topological_order = topological_sort(G)





# 根からの最長経路を計算

dist = [-float('inf')] * N

dist[topological_order[0]] = 0

for n in topological_order:

    for to in G[n]:

        dist[to] = max(dist[to], dist[n] + 1)





ans = [-1] * N

for n in range(N):

    for to in G[n]:

        if dist[n] + 1 == dist[to]:

            ans[to] = n



for p in ans:

    print((p + 1))

import sys

sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(N - 1 + M):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    G[a].append(b)


def topological_sort(g):
    topological_list = []
    visited = set()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.add(n)

    for i in range(len(g)):
        if i not in visited:
            dfs(i)
    return topological_list[::-1]


topological_order = topological_sort(G)
# 根からの最長経路を計算
dist = [-float("inf")] * N
dist[topological_order[0]] = 0
for n in topological_order:
    for to in G[n]:
        dist[to] = max(dist[to], dist[n] + 1)
node_depth = sorted(list(enumerate(dist)), key=lambda x: x[1])
ans = [[node_depth[0][0], -1]]
for n, depth in node_depth:
    for to in G[n]:
        if dist[to] == depth + 1:
            ans.append([to, n])
ans.sort()
for i, p in ans:
    print((p + 1))

import sys

sys.setrecursionlimit(10**9)
N, M = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(N - 1 + M):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    G[a].append(b)


def topological_sort(g):
    topological_list = []
    visited = set()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.add(n)

    for i in range(len(g)):
        if i not in visited:
            dfs(i)
    return topological_list[::-1]


topological_order = topological_sort(G)
# 根からの最長経路を計算
dist = [-float("inf")] * N
dist[topological_order[0]] = 0
for n in topological_order:
    for to in G[n]:
        dist[to] = max(dist[to], dist[n] + 1)
ans = [-1] * N
for n in range(N):
    for to in G[n]:
        if dist[n] + 1 == dist[to]:
            ans[to] = n
for p in ans:
    print((p + 1))

-node_depth = sorted(list(enumerate(dist)), key=lambda x: x[1]) -ans = [[node_depth[0][0], -1]] -for n, depth in node_depth: +ans = [-1] * N +for n in range(N): -        if dist[to] == depth + 1: -            ans.append([to, n]) -ans.sort() -for i, p in ans: +        if dist[n] + 1 == dist[to]: +            ans[to] = n +for p in ans: