import sys

from collections import deque



sys.setrecursionlimit(10 ** 5 + 100)



n, m = list(map(int, input().split()))

links = [set() for _ in range(n)]

root = set(range(n))

for line in sys.stdin.readlines():

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

    a -= 1

    b -= 1

    links[a].add(b)

    root.discard(b)

root = root.pop()



parents = [set() for _ in range(n)]

q = deque([(root, -1)])



while q:

    v, p = q.popleft()

    parents[v].add(p)

    if len(parents[v]) > 1:

        continue

    q.extend((c, v) for c in links[v])



fixed = [-1] * n



# print(parents)



q = deque([(root, -1)])

while q:

    v, p = q.popleft()

    pv = parents[v]

    pv.remove(p)

    if len(pv) == 0:

        fixed[v] = p

        q.extend((c, v) for c in links[v])



print(('\n'.join(str(p + 1) for p in fixed)))

import sys

from collections import deque



n, m = list(map(int, input().split()))

links = [set() for _ in range(n)]

in_counts = [0] * n

for line in sys.stdin.readlines():

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

    a -= 1

    b -= 1

    links[a].add(b)

    in_counts[b] += 1



root = 0

for v, ic in enumerate(in_counts):

    if ic == 0:

        root = v

        break



parents = [-1] * n

q = deque([(c, root) for c in links[root]])



while q:

    v, p = q.popleft()

    in_counts[v] -= 1

    if in_counts[v] == 0:

        parents[v] = p

        q.extend((c, v) for c in links[v])



print(('\n'.join(str(p + 1) for p in parents)))

import sys
from collections import deque

sys.setrecursionlimit(10**5 + 100)
n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
root = set(range(n))
for line in sys.stdin.readlines():
    a, b = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add(b)
    root.discard(b)
root = root.pop()
parents = [set() for _ in range(n)]
q = deque([(root, -1)])
while q:
    v, p = q.popleft()
    parents[v].add(p)
    if len(parents[v]) > 1:
        continue
    q.extend((c, v) for c in links[v])
fixed = [-1] * n
# print(parents)
q = deque([(root, -1)])
while q:
    v, p = q.popleft()
    pv = parents[v]
    pv.remove(p)
    if len(pv) == 0:
        fixed[v] = p
        q.extend((c, v) for c in links[v])
print(("\n".join(str(p + 1) for p in fixed)))

import sys
from collections import deque

n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
in_counts = [0] * n
for line in sys.stdin.readlines():
    a, b = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add(b)
    in_counts[b] += 1
root = 0
for v, ic in enumerate(in_counts):
    if ic == 0:
        root = v
        break
parents = [-1] * n
q = deque([(c, root) for c in links[root]])
while q:
    v, p = q.popleft()
    in_counts[v] -= 1
    if in_counts[v] == 0:
        parents[v] = p
        q.extend((c, v) for c in links[v])
print(("\n".join(str(p + 1) for p in parents)))

-sys.setrecursionlimit(10**5 + 100) -root = set(range(n)) +in_counts = [0] * n -    root.discard(b) -root = root.pop() -parents = [set() for _ in range(n)] -q = deque([(root, -1)]) +    in_counts[b] += 1 +root = 0 +for v, ic in enumerate(in_counts): +    if ic == 0: +        root = v +        break +parents = [-1] * n +q = deque([(c, root) for c in links[root]]) -    parents[v].add(p) -    if len(parents[v]) > 1: -        continue -    q.extend((c, v) for c in links[v]) -fixed = [-1] * n -# print(parents) -q = deque([(root, -1)]) -while q: -    v, p = q.popleft() -    pv = parents[v] -    pv.remove(p) -    if len(pv) == 0: -        fixed[v] = p +    in_counts[v] -= 1 +    if in_counts[v] == 0: +        parents[v] = p -print(("\n".join(str(p + 1) for p in fixed))) +print(("\n".join(str(p + 1) for p in parents)))