nv, ne = map(int, input().split(' '))

in_degs = [0] * nv

q = []

outs = {}

o = []



for _ in range(ne):

    s, t = map(int, input().split(' '))



    if s in outs: outs[s].append(t)

    else: outs[s] = [t]



    in_degs[t] += 1



for i in range(nv):

    if in_degs[i] == 0: q.append(i)



while len(q) > 0:

    v = q.pop(0)

    o.append(v)



    if v in outs:

        for out in outs[v]:

            in_degs[out] -= 1

            if in_degs[out] == 0: q.append(out)



[print(v) for v in o]

nv, ne = map(int, input().split(' '))

in_degs = [0] * nv

q = []

outs = {}

o = []



for _ in range(ne):

    s, t = map(int, input().split(' '))



    if s in outs: outs[s].append(t)

    else: outs[s] = [t]



    in_degs[t] += 1



for i in range(nv):

    if in_degs[i] == 0: q.append(i)



while q:

    v = q.pop(0)

    o.append(v)



    if v in outs:

        for out in outs[v]:

            in_degs[out] -= 1

            if in_degs[out] == 0: q.append(out)



[print(v) for v in o]

nv, ne = map(int, input().split(" "))
in_degs = [0] * nv
q = []
outs = {}
o = []
for _ in range(ne):
    s, t = map(int, input().split(" "))
    if s in outs:
        outs[s].append(t)
    else:
        outs[s] = [t]
    in_degs[t] += 1
for i in range(nv):
    if in_degs[i] == 0:
        q.append(i)
while len(q) > 0:
    v = q.pop(0)
    o.append(v)
    if v in outs:
        for out in outs[v]:
            in_degs[out] -= 1
            if in_degs[out] == 0:
                q.append(out)
[print(v) for v in o]

nv, ne = map(int, input().split(" "))
in_degs = [0] * nv
q = []
outs = {}
o = []
for _ in range(ne):
    s, t = map(int, input().split(" "))
    if s in outs:
        outs[s].append(t)
    else:
        outs[s] = [t]
    in_degs[t] += 1
for i in range(nv):
    if in_degs[i] == 0:
        q.append(i)
while q:
    v = q.pop(0)
    o.append(v)
    if v in outs:
        for out in outs[v]:
            in_degs[out] -= 1
            if in_degs[out] == 0:
                q.append(out)
[print(v) for v in o]

-while len(q) > 0: +while q: