#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define vec vector
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; int cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T> ostream& operator << (ostream& s, const set<T>& se) {
   s << "{";
   for (auto i = se.begin(); i != se.end(); ++i) {
      s << *i;
      if (next(i) != se.end()) s << ", ";
   }
   s << "}";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

void topological_sort(const vector<vector<int>>& G, vector<int>& idx)
{
   vec<int> num(G.size(),0);
   REP(i, 0, G.size()) {
      REP(j, 0, G[i].size()) {
         num[G[i][j]]++;
      }
   }
   stack<int> st;
   for(int i = 0; i < num.size(); i++) {
      if (num[i] == 0) {
         st.push(i);
      }
   }
   int k = 0;
   while (!st.empty()) {
      int i = st.top(); st.pop();
      idx[i] = k;
      for(int j = 0; j < G[i].size(); j++) {
         num[G[i][j]]--;
         if (num[G[i][j]] == 0) {
            st.push(G[i][j]);
         }
      }
      k++;
   }
}

signed main()
{
   int N, M; cin >> N >> M;
   vec<int> A(N-1+M), B(N-1+M);
   REP(i, 0, N-1+M) {
      cin >> A[i] >> B[i];
      A[i]--; B[i]--;
   }

   vec<vec<int>> G(N);
   REP(i, 0, N-1+M) {
      G[A[i]].PB(B[i]);
   }

   vec<int> idx(N);
   topological_sort(G, idx);

   DUMP(idx)

   vec<int> prev(N,-1), d(N, -1);
   REP(i, 0, N) {
      REP(j, 0, SZ(G[i])) {
         int to = G[i][j];
         if (d[to] < idx[i]) {
            d[to] = idx[i];
            prev[to] = i;
         }
      }
   }

   DUMP(prev)
   REP(i, 0, N) {
      cout << prev[i]+1 << endl;
   }

   return 0;
}


Measured memory_bytes: 10224