#include <bits/stdc++.h>
using namespace std;
const long long MXN = 1e6 + 10;
long long n, m;
vector<long long> G[MXN], adj[MXN], adt[MXN], ANS, Top;
bool bad[MXN], indag[MXN], vis[MXN], mark[MXN];
void dfs(long long u) {
  vis[u] = 1;
  for (auto v : adj[u]) {
    if (!vis[v]) dfs(v);
  }
  Top.push_back(u);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    long long u, v;
    cin >> u >> v;
    G[u].push_back(v);
  }
  for (int u = 1; u <= n; u++) {
    if (bad[u]) continue;
    indag[u] = 1;
    for (auto v : G[u]) bad[v] = 1;
  }
  for (int u = 1; u <= n; u++) {
    if (!indag[u]) continue;
    for (auto v : G[u]) {
      if (!indag[v]) continue;
      adj[u].push_back(v), adt[v].push_back(u);
    }
  }
  for (int u = 1; u <= n; u++) {
    if (indag[u] && !vis[u]) dfs(u);
  }
  reverse(Top.begin(), Top.end());
  for (auto u : Top) {
    mark[u] = 1;
    for (auto v : adt[u]) {
      if (mark[v]) mark[u] = 0;
    }
    if (mark[u]) ANS.push_back(u);
  }
  cout << ANS.size() << '\n';
  for (auto X : ANS) cout << X << ' ';
  cout << '\n';
  return 0;
}
