#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct segtree {
	int N, dat[2 * 300000];
	segtree() {}
	segtree(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = INF;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};

struct Edge {
	int src,dst,weight;
};

typedef vector<vector<Edge>> Graph;

bool visit(const Graph &g, int v, vector<int> &order, vector<int> &color) {
	color[v] = 1;
	for(auto e : g[v]) {
		if (color[e.dst] == 2) continue;
		if (color[e.dst] == 1) return false;
		if (!visit(g, e.dst, order, color)) return false;
	}
	order.push_back(v); color[v] = 2;
	return true;
}
bool topologicalSort(const Graph &g, vector<int> &order) {
	int n = g.size();
	vector<int> color(n);
	REP(u, n) if (!color[u] && !visit(g, u, order, color))
		return false;
	reverse(ALL(order));
	return true;
}

signed main(void) {
	int n, m;

	cin >> n >> m;
	Graph g(n);
	vector<int> inc(n);
	REP(i, n + m-1) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--, b--;
		g[a].push_back(Edge{a,b,1});
		inc[b] ++;
	}
	int root = -1;
	REP(i, n) {
		if (inc[i] == 0) {
			root = i;
		}
	}

	if (root == -1) {
		return -1;
	}
	vector<int> order(n),prev(n), dist(n);
	topologicalSort(g, order);

	REP(i, n) {
		int ind = order[i];
		for (auto itr : g[ind]) {
			if (dist[itr.dst] < dist[ind] + 1) {
				prev[itr.dst] = ind;
				dist[itr.dst] = dist[ind] + 1;
			}
		}
	}

	prev[root] = -1;
	REP(i, n) {
		printf("%d\n", prev[i] + 1);
	}

	return 0;
}



Measured memory_bytes: 12528