#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,M;
  cin>>N>>M;
  VI A(N-1+M),B(N-1+M);
  rep(i,N-1+M) cin>>A[i]>>B[i];
  VVI X(N,VI(0));
  VI I(N);
  rep(i,N-1+M){
    X[A[i]-1].pb(B[i]-1);
    I[B[i]-1]++;
  }
  int S=0;
  rep(i,N) if(I[i]==0) S=i;
  VI T(0);
  T.pb(S);
  queue<int> Q;
  Q.push(S);
  VI F(N);
  F[S]++;
  while(!Q.empty()){
    int now=Q.front();
    Q.pop();
    rep(i,X[now].size()){
      int nxt=X[now][i];
      if(!F[nxt]){
        I[nxt]--;
        if(!I[nxt]){
          Q.push(nxt);
          T.pb(nxt);
        }
      }
    }
  }
  VI Z(N);
  rep(i,N){
    int now=T[i];
    if(!Z[now]) Z[now]=1;
    rep(j,X[now].size()){
      int nxt=X[now][j];
      Z[nxt]=max(Z[nxt],Z[now]+1);
    }
  }
  VI ans(N);
  rep(i,N){
    rep(j,X[i].size()){
      int nxt=X[i][j];
      if(Z[i]+1==Z[nxt]) ans[nxt]=i+1;
    }
  }
  ans[S]=0;
  rep(i,N) cout<<ans[i]<<endl;
}

#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int n, m;

#define MAXN (1 << 17)
#define INF (1 << 30)

vector<int> a[MAXN];
vector<int> rev[MAXN];
int p[MAXN];
int v[MAXN]; 
int f[MAXN];

int curt;

void dfs(int cur) {
	v[cur] = 1;
	curt++;
	for (int i = 0; i < a[cur].size(); i++) {
		int nnext = a[cur][i];
		if (!v[nnext]) {
			dfs(nnext);
		}
	}
	curt++;
	f[cur] = curt;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n + m - 1; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		a[t1].push_back(t2);
		rev[t2].push_back(t1);
		p[t2] = t1;
	}

	int s = 1;
	while (p[s]) {
		s = p[s];
	}
	dfs(s);
/*	for (int i = 1; i <= n; i++) {
		cerr << f[i] << " ";
	}	
	cerr << endl;
*/	for (int i = 1; i <= n; i++) {
		int best = INF;
		int bestind = 0;
		for (int j = 0; j < rev[i].size(); j++) {
			int nnext = rev[i][j];
			if (f[nnext] < best) {
				best = f[nnext];
				bestind = nnext;
			}
		}
		cout << bestind << endl;
	}

	return 0;
}
