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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, m;
    scan(n, m);

    auto adj = new int[][](n, 0);
    auto iri = new int[](n);
    auto de = new int[](n);

    foreach (i ; 0 .. n - 1 + m) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
        de[ai]++;
        iri[bi]++;
    }

    int root = -1;
    foreach (i ; 0 .. n) {
        if (iri[i] == 0) {
            root = i;
            break;
        }
    }

    debug {
        writeln("iri", iri);
        writeln("de", de);
    }

    auto p = new int[](n);
    p[] = -1;

    void dfs(int v, int par) {
        if (p[v] == -1) p[v] = par + 1;

        foreach (u ; adj[v]) {
            if (u == par) continue;
            iri[u]--;
        }

        foreach (u ; adj[v]) {
            if (u == par) continue;
            if (p[u] != -1) continue;
            debug {
                writefln("v: %d, u:%d, iri: %d", v, u, iri[u]);
            }
            if (iri[u] == 0) {
                dfs(u, v);
            }
        }
    }

    dfs(root, -1);

    foreach (i ; 0 .. n) {
        writeln(p[i]);
    }
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    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);
        }
    }
}
