import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")



n, m = list(map(int, input().split()))

from collections import defaultdict

ns = defaultdict(set)

pps = [set() for _ in range(n)]

for i in range(n-1+m):

    a,b = list(map(int, input().split()))

    a -= 1

    b -= 1

    ns[a].add(b)

    pps[b].add(a)



for i,s in enumerate(pps):

    if not s:

        r = i

        

def tps(start):

    q = [start]

    # 行きがけ順

    seen = [None] * n

    # 帰りがけ順

    done = [None] * n

    d0 = 0

    d1 = n

    seen[start] = d0

    while q:

        u = q.pop()

        if u>=0:

            q.append(~u)

            for v in ns[u]:

                if done[v] is None:

                    d0 += 1

                    seen[v] = d0

                    q.append(v)

        else:

            d1 -= 1

            done[~u] = d1

    return seen, done



done = [None]*n

seen = [False]*n

def dfs(u, val):

    for v in ns[u]:

        if seen[v]:

            continue

        seen[v] = True

        val = dfs(v, val)

    val = val - 1

    done[u] = val

    return val



dfs(r, n)

# seen, done = tps(r)

ps = [-1] * n

ps[r] = 0

for i in range(n):

    if i==r:

        continue

    val = max(pps[i], key=lambda item: done[item])

    ps[i] = val+1

write("\n".join(map(str, ps)))
import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")



n, m = list(map(int, input().split()))

from collections import defaultdict

ns = defaultdict(set)

pps = [set() for _ in range(n)]

for i in range(n-1+m):

    a,b = list(map(int, input().split()))

    a -= 1

    b -= 1

    ns[a].add(b)

    pps[b].add(a)



for i,s in enumerate(pps):

    if not s:

        r = i

        

def tps(start):

    q = [start]

    # 行きがけ順

    seen = [None] * n

    # 帰りがけ順

    done = [None] * n

    d0 = 0

    d1 = n

    while q:

        u = q.pop()

        if u>=0:

            if seen[u]:

                continue

            seen[u] = d0

            d0 += 1

            q.append(~u)

            for v in ns[u]:

                if seen[v] is None:

                    q.append(v)

        else:

            d1 -= 1

            done[~u] = d1

    return seen, done



done = [None]*n

seen = [False]*n

def dfs(u, val):

    for v in ns[u]:

        if seen[v]:

            continue

        seen[v] = True

        val = dfs(v, val)

    val = val - 1

    done[u] = val

    return val



# dfs(r, n)

seen, done = tps(r)

ps = [-1] * n

ps[r] = 0

for i in range(n):

    if i==r:

        continue

    val = max(pps[i], key=lambda item: done[item])

    ps[i] = val+1

write("\n".join(map(str, ps)))
import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n, m = list(map(int, input().split()))
from collections import defaultdict

ns = defaultdict(set)
pps = [set() for _ in range(n)]
for i in range(n - 1 + m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    ns[a].add(b)
    pps[b].add(a)
for i, s in enumerate(pps):
    if not s:
        r = i


def tps(start):
    q = [start]
    # 行きがけ順
    seen = [None] * n
    # 帰りがけ順
    done = [None] * n
    d0 = 0
    d1 = n
    seen[start] = d0
    while q:
        u = q.pop()
        if u >= 0:
            q.append(~u)
            for v in ns[u]:
                if done[v] is None:
                    d0 += 1
                    seen[v] = d0
                    q.append(v)
        else:
            d1 -= 1
            done[~u] = d1
    return seen, done


done = [None] * n
seen = [False] * n


def dfs(u, val):
    for v in ns[u]:
        if seen[v]:
            continue
        seen[v] = True
        val = dfs(v, val)
    val = val - 1
    done[u] = val
    return val


dfs(r, n)
# seen, done = tps(r)
ps = [-1] * n
ps[r] = 0
for i in range(n):
    if i == r:
        continue
    val = max(pps[i], key=lambda item: done[item])
    ps[i] = val + 1
write("\n".join(map(str, ps)))

import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n, m = list(map(int, input().split()))
from collections import defaultdict

ns = defaultdict(set)
pps = [set() for _ in range(n)]
for i in range(n - 1 + m):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    ns[a].add(b)
    pps[b].add(a)
for i, s in enumerate(pps):
    if not s:
        r = i


def tps(start):
    q = [start]
    # 行きがけ順
    seen = [None] * n
    # 帰りがけ順
    done = [None] * n
    d0 = 0
    d1 = n
    while q:
        u = q.pop()
        if u >= 0:
            if seen[u]:
                continue
            seen[u] = d0
            d0 += 1
            q.append(~u)
            for v in ns[u]:
                if seen[v] is None:
                    q.append(v)
        else:
            d1 -= 1
            done[~u] = d1
    return seen, done


done = [None] * n
seen = [False] * n


def dfs(u, val):
    for v in ns[u]:
        if seen[v]:
            continue
        seen[v] = True
        val = dfs(v, val)
    val = val - 1
    done[u] = val
    return val


# dfs(r, n)
seen, done = tps(r)
ps = [-1] * n
ps[r] = 0
for i in range(n):
    if i == r:
        continue
    val = max(pps[i], key=lambda item: done[item])
    ps[i] = val + 1
write("\n".join(map(str, ps)))

-    seen[start] = d0 +            if seen[u]: +                continue +            seen[u] = d0 +            d0 += 1 -                if done[v] is None: -                    d0 += 1 -                    seen[v] = d0 +                if seen[v] is None: -dfs(r, n) -# seen, done = tps(r) +# dfs(r, n) +seen, done = tps(r)