def topologicalSort(g: list, deg: list):

	ret = []

	q = []

	for i, d in enumerate(deg):

		if not d:

			ret.append(i)

			q.append(i)

	while q:

		cur = q.pop(0)

		for nxt in g[cur]:

			deg[nxt] -= 1

			if not deg[nxt]:

				ret.append(nxt)

				q.append(nxt)

	return ret



def main():

	v, e, *L = list(map(int, open(0).read().split()))

	g = [[] for _ in range(v)]

	rev = [[] for _ in range(v)]

	deg = [0] * v

	for s, t in zip(*[iter(L)] * 2):

		g[s - 1].append(t - 1)

		rev[t - 1].append(s - 1)

		deg[t - 1] += 1

	order = topologicalSort(g, deg)

	idx = [None] * v

	for i, o in enumerate(order):

		idx[o] = i

	ans = [0] * v

	for i in range(v):

		if rev[i]:

			ans[i] = max(rev[i], key=lambda x: idx[x]) + 1

	print(("\n".join(map(str, ans))))



if __name__ == "__main__":

	main()

def main():

	v, e, *L = list(map(int, open(0).read().split()))

	g = [[] for _ in range(v)]

	deg = [0] * v

	for s, t in zip(*[iter(L)] * 2):

		g[s - 1].append(t - 1)

		deg[t - 1] += 1

	q = []

	for i, d in enumerate(deg):

		if not d:

			q.append(i)

	ans = [0] * v

	while q:

		c = q.pop(0)

		for n in g[c]:

			deg[n] -= 1

			if not deg[n]:

				q.append(n)

				ans[n] = c + 1

	print(("\n".join(map(str, ans))))



if __name__ == "__main__":

	main()
def topologicalSort(g: list, deg: list):
    ret = []
    q = []
    for i, d in enumerate(deg):
        if not d:
            ret.append(i)
            q.append(i)
    while q:
        cur = q.pop(0)
        for nxt in g[cur]:
            deg[nxt] -= 1
            if not deg[nxt]:
                ret.append(nxt)
                q.append(nxt)
    return ret


def main():
    v, e, *L = list(map(int, open(0).read().split()))
    g = [[] for _ in range(v)]
    rev = [[] for _ in range(v)]
    deg = [0] * v
    for s, t in zip(*[iter(L)] * 2):
        g[s - 1].append(t - 1)
        rev[t - 1].append(s - 1)
        deg[t - 1] += 1
    order = topologicalSort(g, deg)
    idx = [None] * v
    for i, o in enumerate(order):
        idx[o] = i
    ans = [0] * v
    for i in range(v):
        if rev[i]:
            ans[i] = max(rev[i], key=lambda x: idx[x]) + 1
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

def main():
    v, e, *L = list(map(int, open(0).read().split()))
    g = [[] for _ in range(v)]
    deg = [0] * v
    for s, t in zip(*[iter(L)] * 2):
        g[s - 1].append(t - 1)
        deg[t - 1] += 1
    q = []
    for i, d in enumerate(deg):
        if not d:
            q.append(i)
    ans = [0] * v
    while q:
        c = q.pop(0)
        for n in g[c]:
            deg[n] -= 1
            if not deg[n]:
                q.append(n)
                ans[n] = c + 1
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

-def topologicalSort(g: list, deg: list): -    ret = [] +def main(): +    v, e, *L = list(map(int, open(0).read().split())) +    g = [[] for _ in range(v)] +    deg = [0] * v +    for s, t in zip(*[iter(L)] * 2): +        g[s - 1].append(t - 1) +        deg[t - 1] += 1 -            ret.append(i) +    ans = [0] * v -        cur = q.pop(0) -        for nxt in g[cur]: -            deg[nxt] -= 1 -            if not deg[nxt]: -                ret.append(nxt) -                q.append(nxt) -    return ret - - -def main(): -    v, e, *L = list(map(int, open(0).read().split())) -    g = [[] for _ in range(v)] -    rev = [[] for _ in range(v)] -    deg = [0] * v -    for s, t in zip(*[iter(L)] * 2): -        g[s - 1].append(t - 1) -        rev[t - 1].append(s - 1) -        deg[t - 1] += 1 -    order = topologicalSort(g, deg) -    idx = [None] * v -    for i, o in enumerate(order): -        idx[o] = i -    ans = [0] * v -    for i in range(v): -        if rev[i]: -            ans[i] = max(rev[i], key=lambda x: idx[x]) + 1 +        c = q.pop(0) +        for n in g[c]: +            deg[n] -= 1 +            if not deg[n]: +                q.append(n) +                ans[n] = c + 1