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)

  cnt[0] = 1

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

    dic[a].append(b)

    cnt[b] += 1



  for i, m in enumerate(cnt):

    if m==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.append(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)

  cnt[0] = 1

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

    dic[a].append(b)

    cnt[b] += 1



  for i, m in enumerate(cnt):

    if m==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] = m

        q.append(c)



  ans = '\n'.join(map(str,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)
    cnt[0] = 1
    for a, b in zip(*[iter(L)] * 2):
        dic[a].append(b)
        cnt[b] += 1
    for i, m in enumerate(cnt):
        if m == 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.append(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)
    cnt[0] = 1
    for a, b in zip(*[iter(L)] * 2):
        dic[a].append(b)
        cnt[b] += 1
    for i, m in enumerate(cnt):
        if m == 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] = m
                q.append(c)
    ans = "\n".join(map(str, par))
    print(ans)


if __name__ == "__main__":
    main()

-            par[i - 1] = "0" +            par[i - 1] = 0 -                par[c - 1] = str(m) +                par[c - 1] = m -    ans = "\n".join(par) +    ans = "\n".join(map(str, par))