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

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> A(N+M-1),B(N+M-1),G[N],in_cnt(N,0);
	vector<bool> is_root(N,true);

	for(int i=0;i<N+M-1;i++){
		cin >> A[i] >> B[i];
		A[i]--,B[i]--;
		G[A[i]].push_back(B[i]);
		is_root[B[i]] = false;
		in_cnt[B[i]]++;
	}

	int root;
	for(int i=0;i<N-1;i++){
		if(is_root[i]) root = i;
	}

	vector<ll> pa(N,-1);
	queue<ll> q;
	q.push(root);

	while(q.size()){
		ll from = q.front();
		q.pop();
		for(auto to:G[from]){
			pa[to] = from;
			in_cnt[to]--;
			if(in_cnt[to] == 0){
				q.push(to);
			}
		}
	}

	pa[root] = -1;
	for(auto x:pa){
		cout << x+1 << "\n";
	}

}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

vector<int> g[N], ans;
bool bio[N];
int parent[N];

void dfs(int u) {
  bio[u] = true;
  for (int v: g[u]) {
    if (bio[v]) continue;
    dfs(v);
  }
  ans.push_back(u);
}

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  for (int u, v, i = 0; i < n-1+m; ++i) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; ++i) {
    if (bio[i]) continue;
    dfs(i);
  }
  for (int u: ans)
    for (int v: g[u])
      if (!parent[v])
	parent[v] = u;
  for (int i = 1; i <= n; ++i) printf("%d\n", parent[i]);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
