// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long

#define rep(i,n) for(int i=0;i<n;i++)

#define Rep(i,a,b) for(int i=a;i<b;i++)

#define REP(i,a,b) for(int i=a;i<=b;i++)

#define rev(i,n) for(int i=n-1;i>=0;i--)

#define vi vector<int>

#define pb push_back

#define pi pair<int,int>

#define vp vector<pair<int,int> >

#define mp make_pair

#define all(v) (v).begin(),(v).end()

#define fi first

#define se second

#define INF 1000000000

#define eps 1e-7

#define mod 1000000007

#define int ll

using namespace std;



int P[100000 + 10];

vector<pi> edge; //fiが終点 seが始点

set<int> l_to_r[100000 + 10];

set<int> r_to_l[100000 + 10];



signed main(void) {

    int N, M;

    cin >> N >> M;



    set<int> S;

    REP(i, 1, N) S.insert(i);

    rep(i, N-1+M) {

        int A, B;

        cin >> A >> B;

        edge.pb(mp(B, A));

        l_to_r[A].insert(B);

        r_to_l[B].insert(A);

        if (S.count(B)) S.erase(B);

    }

    int root = *(S.begin());

    // cout << root << endl;

    stack<int> T;

    T.push(root);

    // int removed_num = 0;



    while(T.size() > 0) {

        int top = T.top();

        T.pop();

        for (auto e : l_to_r[top]) {

            if (r_to_l[e].size() == 1) {

                P[e] = top;

                T.push(e);

            } else {

                r_to_l[e].erase(top);

                // removed_num++;

            }

        }

    }



    // REP(i, 1, N) {

    //     printf("l_to_r[%lld]の中身:\n", i);

    //     for (auto e : l_to_r[i]) cout << e << endl;

    //     printf("r_to_l[%lld]の中身:\n", i);

    //     for (auto e : r_to_l[i]) cout << e << endl;

    //     printf("P[%lld] = %lld\n", i, P[i]);

    // }

    

    REP(i, 1, N) {

        if (P[i] == i) cout << 0 << endl;

        else cout << P[i] << endl;

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.3651227608243075x):
#include <bits/stdc++.h>

#define ll long long

#define rep(i,n) for(int i=0;i<n;i++)

#define Rep(i,a,b) for(int i=a;i<b;i++)

#define REP(i,a,b) for(int i=a;i<=b;i++)

#define rev(i,n) for(int i=n-1;i>=0;i--)

#define vi vector<int>

#define pb push_back

#define pi pair<int,int>

#define vp vector<pair<int,int> >

#define mp make_pair

#define all(v) (v).begin(),(v).end()

#define fi first

#define se second

#define INF 1000000000

#define eps 1e-7

#define mod 1000000007

#define int ll

using namespace std;



int P[100000 + 10];

vi adj[100000 + 10];

int in_deg[100000 + 10];



signed main(void) {

    int N, M;

    cin >> N >> M;

    

    REP(i, 1, N) P[i] = i;



    rep(i, N-1+M) {

        int A, B;

        cin >> A >> B;

        in_deg[B]++;

        adj[A].push_back(B);

    }

    

    /* breadth first search */

    queue<int> Q;

    REP(i, 1, N) if (in_deg[i] == 0) Q.push(i);

    while(!Q.empty()) {

        int top = Q.front();

        Q.pop();

        for (auto node : adj[top]) {

            in_deg[node]--;

            if (in_deg[node] == 0) {

                Q.push(node);

                P[node] = top;

            }

        }

    }

    

    REP(i, 1, N) {

        if (P[i] == i) cout << 0 << endl;

        else cout << P[i] << endl;

    }



    return 0;

}