import sys
sys.setrecursionlimit(2000000)
n,m = map(int,input().split())
g2 = [[] for i in range(n)]
g = [[] for i in range(n)]
for i in range(n-1+m):
        a,b = map(int,input().split())
        g2[b-1].append(a-1)
        g[a-1].append(b-1)
for j in range(n):
        if len(g2[j]) == 0:
                ne = j
                break
ans = [[-1,-1] for i in range(n)]
ans[ne] = [0,0]
def dfs(x,y,z):
        for i in g[x]:
                if i == y:
                        continue
                if ans[i][1] < z+1:
                        ans[i] = [x+1,z+1]
                        dfs(i,x,z+1)
dfs(ne,-1,0)
for i,j in ans:
        print(i)