#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

template<typename T> void sort(vector<T>& v) {sort(v.begin(), v.end());}

template<typename Edge> struct FullEdge : public Edge {
  int from;

  FullEdge() = default;

  FullEdge(const int from, const Edge& edge) : Edge(edge), from(from) {}
};

struct Edge {
  using CostType = int;
  const static int cost = 1;
  int to;
  Edge(int to = -1) : to(to) {}
  bool isNone() const {return to == -1;}
};

istream& operator>>(istream& s, FullEdge<Edge>& edge) {
  s >> edge.from >> edge.to;
  return s;
}

ostream& operator<<(ostream& s, const FullEdge<Edge>& edge) {
  s << '(' << edge.from << ',' << edge.to << ')';
  return s;
}

template<typename Cost> struct WeightedEdge : public Edge {
  using CostType = Cost;
  Cost cost;
  WeightedEdge(int to = -1, Cost cost = 0) : Edge(to), cost(cost) {}
};

template<typename Cost> istream& operator>>(istream& s, FullEdge<WeightedEdge<Cost>>& edge) {
  s >> edge.from >> edge.to >> edge.cost;
  return s;
}

template<typename Cost> ostream& operator<<(ostream& s, const FullEdge<WeightedEdge<Cost>>& edge) {
  s << '(' << edge.from << ',' << edge.to << ',' << edge.cost << ')';
  return s;
}

template<typename Capacity> struct ResidualEdge : public Edge {
  using CapacityType = Capacity;
  Capacity cap;
  int rev;
  ResidualEdge(int to = -1, Capacity cap = 0) : Edge(to), cap(cap) {}
  ResidualEdge reverse(int from) const {return ResidualEdge(from, 0);}
};

template<typename Capacity, typename Cost> struct WeightedResidualEdge : public ResidualEdge<Capacity> {
  Cost cost;
  WeightedResidualEdge(int to = -1, Capacity cap = 0, Cost cost = 0) : ResidualEdge<Capacity>(to, cap), cost(cost) {}
  WeightedResidualEdge reverse(int from) const {return WeightedResidualEdge(from, 0, -cost);}
};

template<typename Edge> class Graph {
public:
  using EdgeType = Edge;
  virtual int size() const = 0;
  template<typename... Args> void addEdge(int from, int to, Args...) {
    (void)from;
    (void)to;
  }
  template<typename... Args> void addUndirectedEdge(int from, int to, Args...) {
    (void)from;
    (void)to;
  }

  vector<FullEdge<Edge>> getAllEdges() const {
    vector<FullEdge<Edge>> res;
    for (int i = 0; i < size(); ++i) {
      for (const auto& edge : getEdges(i)) {
        res.emplace_back(i, edge);
      }
    }
    return res;
  }

  virtual vector<Edge> getEdges(int from) const = 0;
  virtual Edge getEdge(int from, int to) const = 0;
  virtual bool hasEdge(int from, int to) const = 0;

  int getDegree(int v) const {
    return getEdges(v).size();
  }

  vector<int> getIndegree() const {
    vector<int> degree(size());
    for (const auto& edge : getAllEdges()) ++degree[edge.to];
    return degree;
  }
};

template<typename Graph> Graph readGraph(int n, int m, bool undirected = true, bool one_origin = true) {
  Graph graph(n);
  for (int i = 0; i < m; ++i) {
    FullEdge<typename Graph::EdgeType> edge;
    cin >> edge;
    if (one_origin) {
      --edge.from;
      --edge.to;
    }
    if (undirected) graph.addUndirectedEdge(edge);
    else graph.addEdge(edge);
  }
  return graph;
}

template<typename Edge> class AdjacencyList : public Graph<Edge> {
protected:
  vector<vector<Edge>> graph;

public:
  using EdgeType = Edge;

  AdjacencyList() = default;

  AdjacencyList(int n) : graph(n) {}

  int size() const {
    return graph.size();
  }
  
  template<typename... Args> void addEdge(int from, int to, Args... args) {
    graph[from].emplace_back(to, args...);
  }

  void addEdge(const FullEdge<Edge>& edge) {
    graph[edge.from].emplace_back(edge);
  }

  template<typename... Args> void addUndirectedEdge(int from, int to, Args... args) {
    addEdge(from, to, args...);
    addEdge(to, from, args...);
  }

  void addUndirectedEdge(FullEdge<Edge> edge) {
    graph[edge.from].emplace_back(edge);
    swap(edge.from, edge.to);
    graph[edge.from].emplace_back(edge);
  }

  vector<Edge> getEdges(int from) const {
    return graph[from];
  }

  Edge getEdge(int from, int to) const {
    Edge res;
    for (const auto& edge : graph[from]) {
      if (edge.to == to) res = edge;
    }
    return res;
  }

  bool hasEdge(int from, int to) const {
    for (const auto& edge : graph[from]) {
      if (edge.to == to) return true;
    }
    return false;
  }

  vector<Edge>& operator[](int v) {
    return graph[v];
  }

  const vector<Edge>& operator[](int v) const {
    return graph[v];
  }
};

template<typename Edge> istream& operator>>(istream& s, AdjacencyList<Edge>& graph) {
  int n, m;
  cin >> n >> m;
  graph = readGraph<AdjacencyList<Edge>>(n, m);
  return s;
}

int main() {
  int n, m;
  cin >> n >> m;
  AdjacencyList<Edge> graph1(n), graph2(n);
  for (int i = 0; i < n - 1 + m; ++i) {
    int a, b;
    cin >> a >> b;
    graph1.addEdge(a - 1, b - 1);
    graph2.addEdge(b - 1, a - 1);
  }
  queue<int> que;
  vector<int> depth(n, -1);
  vector<bool> used(n), visited(n);
  for (int i = 0; i < n; ++i) {
    if (graph2.getDegree(i) == 0) {
      que.emplace(i);
      depth[i] = 0;
      used[i] = true;
    }
  }
  vector<int> p(n, -1);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    visited[v] = true;
    for (Edge e : graph1[v]) {
      if (!used[e.to]) {
        bool done = true;
        for (Edge edge : graph2[e.to]) {
          if (depth[edge.to] == -1 || depth[edge.to] >= depth[v] + 1) done = false;
        }
        if (!done) continue;
        p[e.to] = v;
        depth[e.to] = depth[v] + 1;
        que.emplace(e.to);
        used[e.to] = true;
      }
    }
  }
  for (int i = 0; i < n; ++i) cout << p[i] + 1 << endl;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (p[i] == -1) ++cnt;
  }
}



Measured memory_bytes: 12544