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

def main():

  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)

  

if __name__== '__main__':

  main()
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


def main():
    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)


if __name__ == "__main__":
    main()

-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) + +def main(): +    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) + + +if __name__ == "__main__": +    main()