#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1000005;
int N, M, num, col[MAXN];
vector<int> edge[MAXN], rev[MAXN];
stack<int> s;
void dfs(int now) {
  for (auto i : edge[now]) {
    if (col[i]) {
      continue;
    }
    col[i] = 1;
  }
}
void proc(int now) {
  for (auto i : rev[now]) {
    if (col[i] == 2) {
      col[now] = 1;
      return;
    }
  }
  num++;
  col[now] = 2;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    edge[x].push_back(y);
    rev[y].push_back(x);
  }
  for (int i = 0; i < N; i++) {
    if (!col[i]) {
      col[i] = 3;
      dfs(i);
      s.push(i);
    }
  }
  while (!s.empty()) {
    proc(s.top());
    s.pop();
  }
  cout << num << "\n";
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (col[i] == 2) cnt++, cout << i + 1 << " ";
  }
  while (cnt != num)
    ;
  cout << endl;
  return 0;
}
