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

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

    dic[a-1] += [b-1]

    cnt[b-1] += 1



  for i in range(N):

    if cnt[i]==0:

      q = deque([i])

      par[i] = '0'

      break

  

  while q:

    m = q.popleft()

    for c in dic[m]:

      cnt[c] -= 1

      if cnt[c]==0:

        par[c] = str(m+1)

        q += [c]



  ans = '\n'.join(par)

  print(ans)

  

if __name__== '__main__':

  main()

from collections import defaultdict, deque

def main():

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

  dic = defaultdict(list)

  par =  [None]*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


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


if __name__ == "__main__":
    main()

from collections import defaultdict, deque


def main():
    N, M, *L = list(map(int, open(0).read().split()))
    dic = defaultdict(list)
    par = [None] * 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()

-    par = [0] * N -    cnt = [0] * N +    par = [None] * N +    cnt = [0] * (N + 1) -        dic[a - 1] += [b - 1] -        cnt[b - 1] += 1 -    for i in range(N): +        dic[a] += [b] +        cnt[b] += 1 +    for i in range(1, N + 1): -            par[i] = "0" +            par[i - 1] = "0" -                par[c] = str(m + 1) +                par[c - 1] = str(m)