from collections import defaultdict, deque

N, M, *L = list(map(int, open(0).read().split()))

dic = defaultdict(list)

par =  [0]*(N+1)

cnt = [0]*(N+1)

for a,b in zip(*[iter(L)]*2):

  dic[a] += [b]

  cnt[b] += 1



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

  if cnt[i]==0:

    q = deque([i])

    break

  

while q:

  m = q.popleft()

  for c in dic[m]:

    cnt[c] -= 1

    if cnt[c]==0:

      par[c] = m

      q += [c]



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

  print((par[i]))
from collections import defaultdict, deque

N, M, *L = list(map(int, open(0).read().split()))

dic = defaultdict(list)

par =  [0]*N

cnt = [0]*(N+1)

for a,b in zip(*[iter(L)]*2):

  dic[a] += [b]

  cnt[b] += 1



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

  if cnt[i]==0:

    q = deque([i])

    par[i-1] = '0'

    break

  

while q:

  m = q.popleft()

  for c in dic[m]:

    cnt[c] -= 1

    if cnt[c]==0:

      par[c-1] = str(m)

      q += [c]



ans = '\n'.join(par)

print(ans)
from collections import defaultdict, deque

N, M, *L = list(map(int, open(0).read().split()))
dic = defaultdict(list)
par = [0] * (N + 1)
cnt = [0] * (N + 1)
for a, b in zip(*[iter(L)] * 2):
    dic[a] += [b]
    cnt[b] += 1
for i in range(1, N + 1):
    if cnt[i] == 0:
        q = deque([i])
        break
while q:
    m = q.popleft()
    for c in dic[m]:
        cnt[c] -= 1
        if cnt[c] == 0:
            par[c] = m
            q += [c]
for i in range(1, N + 1):
    print((par[i]))

from collections import defaultdict, deque

N, M, *L = list(map(int, open(0).read().split()))
dic = defaultdict(list)
par = [0] * N
cnt = [0] * (N + 1)
for a, b in zip(*[iter(L)] * 2):
    dic[a] += [b]
    cnt[b] += 1
for i in range(1, N + 1):
    if cnt[i] == 0:
        q = deque([i])
        par[i - 1] = "0"
        break
while q:
    m = q.popleft()
    for c in dic[m]:
        cnt[c] -= 1
        if cnt[c] == 0:
            par[c - 1] = str(m)
            q += [c]
ans = "\n".join(par)
print(ans)

-par = [0] * (N + 1) +par = [0] * N +        par[i - 1] = "0" -            par[c] = m +            par[c - 1] = str(m) -for i in range(1, N + 1): -    print((par[i])) +ans = "\n".join(par) +print(ans)