import sys

sys.setrecursionlimit(10 ** 9)



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

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

G_rev = [set() 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)

    # 親と子を逆に

    G_rev[b].add(a)





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)





parents = [set(G_rev[i]) for i in range(N)]

for t in topological_order[::-1]:

    for p in G_rev[t]:

        parents[t] |= parents[p]





ans = [-1] * N

for t in topological_order:

    for child in G[t]:

        for p in G_rev[child]:

            if t in parents[p]:

                flg = True

                break

        else:

            ans[child] = t



for a in ans:

    print((a + 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)]
G_rev = [set() 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)
    # 親と子を逆に
    G_rev[b].add(a)


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)
parents = [set(G_rev[i]) for i in range(N)]
for t in topological_order[::-1]:
    for p in G_rev[t]:
        parents[t] |= parents[p]
ans = [-1] * N
for t in topological_order:
    for child in G[t]:
        for p in G_rev[child]:
            if t in parents[p]:
                flg = True
                break
        else:
            ans[child] = t
for a in ans:
    print((a + 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))

-G_rev = [set() for i in range(N)] -    # 親と子を逆に -    G_rev[b].add(a) -parents = [set(G_rev[i]) for i in range(N)] -for t in topological_order[::-1]: -    for p in G_rev[t]: -        parents[t] |= parents[p] -ans = [-1] * N -for t in topological_order: -    for child in G[t]: -        for p in G_rev[child]: -            if t in parents[p]: -                flg = True -                break -        else: -            ans[child] = t -for a in ans: -    print((a + 1)) +# 根からの最長経路を計算 +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))