#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
vector<int> g[(int)2e6];
vector<int> used(2e6), del(2e6), ans;
void dfs(int x) {
  used[x] = 1;
  if (!del[x]) {
    del[x] = 1;
    ans.push_back(x);
    for (int i : g[x]) {
      del[i] = 1;
    }
  }
  for (int i : g[x]) {
    if (!used[i]) dfs(i);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(20);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) dfs(i);
  }
  reverse(ans.begin(), ans.end());
  int cnt = 0;
  for (int i : ans) {
    if (used[i] == 3) continue;
    bool flag = true;
    for (int x : g[i]) {
      if (used[x] == 2) flag = false;
    }
    if (flag) {
      used[i] = 2, cnt++;
      for (int x : g[i]) {
        used[x] = 3;
      }
    }
  }
  cout << cnt << endl;
  for (int i : ans) {
    if (used[i] == 2) cout << i << " ";
  }
}
