#include <bits/stdc++.h>
namespace hanano {
inline void PAUSE() {}
inline void redirect_file(const char in[] = "input.in",
                          const char ot[] = "output.o") {}
inline void cpp_IO_boost() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0), std::cout.tie(0);
}
template <class T>
inline T fastpow(T a, int p, T mod = -1) {
  if (mod != -1) a %= mod;
  T base = a, ret = 1;
  while (p) {
    if (p & 1) {
      ret *= base;
      if (mod != -1) ret %= mod;
    }
    base *= base;
    if (mod != -1) base %= mod;
    p >>= 1;
  }
  return ret;
}
template <class T>
bool read(T &num) {
  int ch;
  while (1) {
    ch = getchar();
    if (ch == EOF) return false;
    if (ch >= '0' && ch <= '9') {
      num = T(ch - '0');
      break;
    }
  }
  while (1) {
    ch = getchar();
    if (ch == EOF) return false;
    if (ch >= '0' && ch <= '9')
      num = num * T(10) + T(ch - '0');
    else
      break;
  }
  return true;
}
template <class T>
bool read(T &num1, T &num2) {
  return read(num1) && read(num2);
}
template <class T>
bool read(T &num1, T &num2, T &num3) {
  return read(num1) && read(num2) && read(num3);
}
template <class T, class _Pr>
inline void sort_all(std::vector<T> &a, _Pr cmp) {
  std::sort(a.begin(), a.end(), cmp);
}
template <class T>
inline void sort_all(std::vector<T> &a) {
  std::sort(a.begin(), a.end());
}
template <class T1, class T2>
struct tuple2 {
  T1 x;
  T2 y;
  tuple2() = default;
  explicit tuple2(T1 x, T2 y) : x(x), y(y) {}
  bool operator<(const tuple2 a) const { return this->y < a.y; }
};
template <class T1, class T2, class T3>
struct tuple3 {
  T1 x;
  T2 y;
  T3 z;
  tuple3() = default;
  explicit tuple3(T1 x, T2 y, T3 z) : x(x), y(y), z(z) {}
  bool operator<(const tuple3 a) const { return this->z < a.z; }
};
}  // namespace hanano
const int N = 1e6 + 10;
using namespace std;
using namespace hanano;
struct Edge {
  int from, to;
  explicit Edge(int from, int to) : from(from), to(to) {}
  Edge() = default;
};
int n, m;
vector<int> node[N], pre_node[N];
vector<Edge> edges, pre_edges;
bool vis[N];
set<int> ans;
stack<int> sv;
void addedge(int from, int to) {
  edges.push_back(Edge(from, to));
  node[from].push_back(edges.size() - 1);
  pre_edges.push_back(Edge(to, from));
  pre_node[to].push_back(edges.size() - 1);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    addedge(from, to);
  }
  for (int i = 1; i <= n; i++) vis[i] = 1;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) {
      sv.push(i);
      vis[i] = 0;
      for (int j = 0; j < node[i].size(); j++) {
        vis[edges[node[i][j]].to] = 0;
      }
    }
  }
  while (!sv.empty()) {
    int tp = sv.top();
    sv.pop();
    bool flag = false;
    for (int i = 0; i < pre_node[tp].size(); i++) {
      int to = pre_edges[pre_node[tp][i]].to;
      if (ans.count(to)) {
        flag = true;
        break;
      }
    }
    if (!flag) ans.insert(tp);
  }
  cout << ans.size() << endl;
  for (auto val : ans) {
    printf("%d ", val);
  }
  cout << endl;
  PAUSE();
  return 0;
}
