#include <bits/stdc++.h>
using std::pair;
using std::string;
using std::vector;
template <typename T>
bool chkmax(T& a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T& a, T b) {
  return a > b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
string procStatus() {
  std::ifstream t("/proc/self/status");
  return string(std::istreambuf_iterator<char>(t),
                std::istreambuf_iterator<char>());
}
template <typename T>
T read(T& x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
  return x *= f;
}
const int N = 1000000;
int n, m;
vector<int> G[N + 5], ans;
int con[N + 5], ban[N + 5];
int main() {
  read(n), read(m);
  for (int i = 1; i <= m; ++i) {
    static int u, v;
    read(u), read(v), G[u].push_back(v);
  }
  for (int i = 1; i <= n; ++i)
    if (!con[i]) {
      con[i] = 1;
      for (const auto& v : G[i])
        if (!con[v]) con[v] = 2;
    }
  for (int i = n; i >= 1; --i)
    if (con[i] == 1 && !ban[i]) {
      ans.push_back(i);
      for (const auto& v : G[i]) ban[v] = 1;
    }
  printf("%d\n", (int)ans.size());
  for (const auto& v : ans) printf("%d ", v);
  return 0;
}
