#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <typename T>
vector<T> toposort(const set<T> group, const set<pair<T,T>>& arcs) {
    map<T, set<T>> from, to;
    for (pair<T,T> arc: arcs) {
        T u = arc.first, v = arc.second;
        from[u].insert(v);
        to[v].insert(u);
    }
    int E = arcs.size();

    set<T> S;
    for (T i : group) {
        if (!found(to, i)) S.insert(i);
    }

    vector<T> L;
    while (!S.empty()) {
        T u = *S.begin();
        S.erase(u);
        L.push_back(u);
        for (T v: from[u]) {
            to[v].erase(u);
            --E;
            if (to[v].empty()) {
                S.insert(v);
            }
        }
    }

    if (E != 0) {
        return vector<T> {};
    }

    return L;
}

void solve(int N,int M,vi& a,vi& b) {
    int L=a.size(); // N-1+M
    vvi nxt(L), into(L);
    rep(i,L){
        nxt[a[i]].pb(b[i]);
        into[b[i]].pb(a[i]);
    }
    int root=-1;
    vi leaf;
    rep(i,L){
        if (into[i].size()==0) root=i;
        if (nxt[i].size()==0) leaf.pb(i);
    }

    set<int> group;
    rep(i,N) group.insert(i);
    set<ii> arcs;
    rep(i,L) arcs.insert(ii(a[i],b[i]));
    vi ord = toposort(group, arcs);
#ifdef DEBUG
    cerr << ord << endl;
#endif
    vi ordn(N);
    rep(i,N) ordn[ ord[i] ] = i;

    vi previ(N, -1);
    for (int u: ord){
        // visited[u] = true;
        int omax=-1;
        for (int f: into[u]) {
            if (ordn[f] > omax) {
                previ[u] = f;
                omax = ordn[f];
            }
        }
    }
#ifdef DEBUG
    cerr << previ << endl;
#endif
    rep(i,N){
        printf("%d\n", previ[i]+1);
    }
}

int main() {
    int N,M; scanf("%d%d",&N,&M);
    vi a(N-1+M), b(N-1+M);
    rep(i,N-1+M){
        scanf("%d%d",&a[i],&b[i]);
        --a[i]; --b[i];
    }
    solve(N,M,a,b) ;
    return 0;
}


Measured memory_bytes: 56440