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);
    scan(m);

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

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

    int num = 1;

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

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

        rank[num++] = v;
    }

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

    writefln("%(%s\n%)", rank[1 .. $]);

    bool uniq = true;

    foreach (i ; 1 .. n) {
        int a = rank[i], b = rank[i + 1];

        bool exist = false;

        foreach (u ; adj[b]) {
            if (u == a) exist = true;
        }

        uniq &= exist;
    }

    writeln(uniq ? 0 : 1);
}


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);
        }
    }
}