import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int n, m;

    scan(n, m);

    auto visited = new bool[](n);
    auto adj = new int[][](n, 0);
    auto rank = new int[](n);

    foreach (i ; 0 .. m) {
        int si, ti;
        scan(si, ti);
        adj[si] ~= ti;
    }

    int num = n - 1;

    void dfs(int v) {
        visited[v] = true;

        foreach (u ; adj[v]) {
            if (!visited[u]) dfs(u);
        }

        rank[num--] = v;
    }

    foreach (i ; 0 .. n) {
        if (!visited[i]) dfs(i);
    }

    writefln("%(%s\n%)", rank);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}