#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> v[100009];
int d[100009];

int ds(int n)
{
	if (v[n].size() == 0) 
		return d[n] = 0;
	if (d[n] != 0) return d[n];
	for (int i = 0; i < v[n].size(); i++)
		d[n] = max(d[n], ds(v[n][i]) + 1);
	return d[n];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n + m - 1; i++) {
		int a, b; cin >> a >> b;
		v[b].push_back(a);
	}
	for (int i = 1; i <= n; i++)
		if (d[i] == 0)
			ds(i);
	for (int i = 1; i <= n; i++) {
		if (d[i] == 0) {
			cout << 0 << '\n';
			continue;
		}
		for (int j = 0; j < v[i].size(); j++)
			if (d[i] - 1 == d[v[i][j]]) {
				cout << v[i][j] << '\n';
				break;
			}
	}
	return 0;
}