#include <bits/stdc++.h>
using namespace std;
using cat = long long;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  vector<vector<int> > G(N), Gi(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    G[--u].push_back(--v);
    Gi[v].push_back(u);
  }
  queue<int> q;
  vector<bool> in_q(N, false), removed(N, false);
  vector<bool> has_link(N, false), has_backlink(N, false);
  for (int i = 0; i < N; i++)
    if (!in_q[i]) {
      q.push(i);
      in_q[i] = true;
      while (!q.empty()) {
        if (has_backlink[q.front()] && has_link[q.front()])
          removed[q.front()] = true;
        if (!removed[q.front()]) {
          for (auto it = Gi[q.front()].begin(); it != Gi[q.front()].end(); it++)
            has_backlink[*it] = true;
          for (auto it = G[q.front()].begin(); it != G[q.front()].end(); it++)
            has_link[*it] = true;
        }
        for (auto it = G[q.front()].begin(); it != G[q.front()].end(); it++)
          if (!in_q[i]) {
            in_q[*it] = true;
            q.push(*it);
          }
        q.pop();
      }
    }
  int cnt = N;
  vector<bool> used(N, true);
  for (int i = 0; i < N; i++)
    if (removed[i]) used[i] = false, cnt--;
  vector<int> deg(N, 0);
  for (int i = 0; i < N; i++)
    if (!removed[i])
      for (auto it = G[i].begin(); it != G[i].end(); it++)
        if (!removed[*it]) deg[*it]++;
  for (int i = 0; i < N; i++)
    if (deg[i] == 0 && !removed[i]) q.push(i);
  while (!q.empty()) {
    for (auto it = G[q.front()].begin(); it != G[q.front()].end(); it++)
      if (!removed[*it]) {
        if (used[q.front()] && used[*it]) used[*it] = false, cnt--;
        deg[*it]--;
        if (deg[*it] == 0) q.push(*it);
      }
    q.pop();
  }
  cout << cnt << "\n";
  for (int i = 0; i < N; i++)
    if (used[i]) cout << i + 1 << "\n";
  return 0;
}
