// Brijesh Panara (201601074)
// DAIICT (India)
#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> > 
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

#define MOD 1000000007
#define NAX 200005
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

void FAST()
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    //srand(time(NULL));
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);    

}

struct directed_graph
{
    ll n;
    stack<ll> s;
    vector<ll> component;
    vector<vector<ll> > adj,radj;
    vector<bool> visited1,visited2;
    
    directed_graph(ll n):
    n(n),visited1(n),visited2(n),adj(n),radj(n) {}

    void addEdge(ll u, ll v)
    {
        adj[u].pb(v);
        radj[v].pb(u);
    }

    void init()
    {
        FOR(i,0,n)
        visited1[i]=false,visited2[i]=false;
    }

    void dfs1(ll ver)
    {
        if(visited1[ver]==true)
            return;
        visited1[ver]=true;

        FOR(i,0,adj[ver].size())
        dfs1(adj[ver][i]);

        s.push(ver);
    }

    vector<ll> tsort()
    {
        init();

        FOR(i,0,n)
        if(visited1[i]==false)
        dfs1(i);
        
        vector<ll> ts;
        while(s.size()!=0)
        {
            ts.pb(s.top());
            s.pop();
        }
        return ts;
    }    

    void dfs2(ll ver)
    {
        if(visited2[ver]==true)
            return;
        visited2[ver]=true;

        FOR(i,0,radj[ver].size())
        dfs2(radj[ver][i]);

        component.pb(ver);
    }
    
    vector<vector<ll> > scc()
    {
        init();

        FOR(i,0,n)
        if(visited1[i]==false)
        dfs1(i);
        
        vector<vector<ll> > scc;
        while(s.size()!=0)
        {
            if(visited2[s.top()]==false)
            {
                component.clear();
                dfs2(s.top());
                scc.pb(component);    
            }
            s.pop();
        }
        return scc;
    }
};


int main()
{
    FAST();

    ll n,m;
    cin>>n>>m;

    directed_graph g(n);
    vector<ll> adj[n];
    FOR(i,0,n+m-1)
    {
        ll u,v;
        cin>>u>>v;
        u--;v--;
        g.addEdge(u,v);
        adj[u].pb(v);
        adj[v].pb(u);
    }

    vector<ll> v = g.tsort();

    ll parent[n];
    FOR(i,0,n)
    parent[i]=-1;

    map<ll,ll> pos;
    map<ll,ll> visited;
    FOR(i,0,n)
    {
        ll ver = v[i];
        ll mx = -1;
        FOR(j,0,adj[ver].size())
        {
            ll adjver = adj[ver][j];
            if(visited[adjver]==true)
            {
                if(pos[adjver]>mx)
                {
                    mx = pos[adjver];
                    parent[ver]=adjver;
                }
            }
        }
        visited[v[i]]=true;
        pos[v[i]]=i;
    }

    FOR(i,0,n)
    cout<<parent[i]+1<<endl;

    return 0;
}


Measured memory_bytes: 32048