from collections import defaultdict, deque

N,M=list(map(int,input().split()))



outs = defaultdict(list)

outs_rev = defaultdict(list)

ins = defaultdict(int)

for _ in range(N+M-1):

  v1,v2=list(map(int,input().split()))

  outs[v1].append(v2)

  outs_rev[v2].append(v1)

  ins[v2] += 1

#print(outs,ins)

#print(outs_rev)



q = deque(v1 for v1 in range(1,N+1) if ins[v1] == 0)

res = []

while q:

  v1 = q.popleft()

  res.append(v1)

  for v2 in outs[v1]:

    ins[v2] -= 1

    if ins[v2] == 0:

      q.append(v2)

#print(res)



res_rev=[0]*N

for i in range(N):

  res_rev[res[i]-1]=i

#print(res_rev)



answer_list=[0]*N

for i in range(N):

  r=res[i]

  if not outs_rev[r]:

    answer_list[r-1]=0

  else:

    max_v=-1

    max_index=-1

    for rr in outs_rev[r]:

      ind=res_rev[rr-1]

      if ind>max_index:

        max_v=res[ind]

        max_index=ind

  

    answer_list[r-1]=max_v

    

#print(answer_list)

for ans in answer_list:

  print(ans)
from collections import deque

N,M=list(map(int,input().split()))



outs = [[] for _ in range(N+1)]

outs_rev = [[] for _ in range(N+1)]

ins = [0]*(N+1)

for _ in range(N+M-1):

  v1,v2=list(map(int,input().split()))

  outs[v1].append(v2)

  outs_rev[v2].append(v1)

  ins[v2] += 1

#print(outs,ins)

#print(outs_rev)



q = deque(v1 for v1 in range(N+1) if ins[v1] == 0)

res = []

while q:

  v1 = q.popleft()

  res.append(v1)

  for v2 in outs[v1]:

    ins[v2] -= 1

    if ins[v2] == 0:

      q.append(v2)

#print(res)



res_rev=[0]*(N+1)

for i in range(N):

  res_rev[res[i]]=i

#print(res_rev)



answer_list=[0]*(N+1)

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

  r=res[i]

  if not outs_rev[r]:

    answer_list[r]=0

  else:

    max_v=-1

    max_index=-1

    for rr in outs_rev[r]:

      ind=res_rev[rr]

      if ind>max_index:

        max_v=res[ind]

        max_index=ind

  

    answer_list[r]=max_v

    

#print(answer_list)

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

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

N, M = list(map(int, input().split()))
outs = defaultdict(list)
outs_rev = defaultdict(list)
ins = defaultdict(int)
for _ in range(N + M - 1):
    v1, v2 = list(map(int, input().split()))
    outs[v1].append(v2)
    outs_rev[v2].append(v1)
    ins[v2] += 1
# print(outs,ins)
# print(outs_rev)
q = deque(v1 for v1 in range(1, N + 1) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
# print(res)
res_rev = [0] * N
for i in range(N):
    res_rev[res[i] - 1] = i
# print(res_rev)
answer_list = [0] * N
for i in range(N):
    r = res[i]
    if not outs_rev[r]:
        answer_list[r - 1] = 0
    else:
        max_v = -1
        max_index = -1
        for rr in outs_rev[r]:
            ind = res_rev[rr - 1]
            if ind > max_index:
                max_v = res[ind]
                max_index = ind
        answer_list[r - 1] = max_v
# print(answer_list)
for ans in answer_list:
    print(ans)

from collections import deque

N, M = list(map(int, input().split()))
outs = [[] for _ in range(N + 1)]
outs_rev = [[] for _ in range(N + 1)]
ins = [0] * (N + 1)
for _ in range(N + M - 1):
    v1, v2 = list(map(int, input().split()))
    outs[v1].append(v2)
    outs_rev[v2].append(v1)
    ins[v2] += 1
# print(outs,ins)
# print(outs_rev)
q = deque(v1 for v1 in range(N + 1) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
# print(res)
res_rev = [0] * (N + 1)
for i in range(N):
    res_rev[res[i]] = i
# print(res_rev)
answer_list = [0] * (N + 1)
for i in range(1, N + 1):
    r = res[i]
    if not outs_rev[r]:
        answer_list[r] = 0
    else:
        max_v = -1
        max_index = -1
        for rr in outs_rev[r]:
            ind = res_rev[rr]
            if ind > max_index:
                max_v = res[ind]
                max_index = ind
        answer_list[r] = max_v
# print(answer_list)
for i in range(1, N + 1):
    print((answer_list[i]))

-from collections import defaultdict, deque +from collections import deque -outs = defaultdict(list) -outs_rev = defaultdict(list) -ins = defaultdict(int) +outs = [[] for _ in range(N + 1)] +outs_rev = [[] for _ in range(N + 1)] +ins = [0] * (N + 1) -q = deque(v1 for v1 in range(1, N + 1) if ins[v1] == 0) +q = deque(v1 for v1 in range(N + 1) if ins[v1] == 0) -res_rev = [0] * N +res_rev = [0] * (N + 1) -    res_rev[res[i] - 1] = i +    res_rev[res[i]] = i -answer_list = [0] * N -for i in range(N): +answer_list = [0] * (N + 1) +for i in range(1, N + 1): -        answer_list[r - 1] = 0 +        answer_list[r] = 0 -            ind = res_rev[rr - 1] +            ind = res_rev[rr] -        answer_list[r - 1] = max_v +        answer_list[r] = max_v -for ans in answer_list: -    print(ans) +for i in range(1, N + 1): +    print((answer_list[i]))