#include <bits/stdc++.h>
using namespace std;
inline void read(int &res) {
  char ch;
  for (; !isdigit(ch = getchar());)
    ;
  for (res = ch - '0'; isdigit(ch = getchar()); res = res * 10 + ch - '0')
    ;
}
int n, m, typ[1000006], deg[1000006];
int info[1000006], Prev[1000006 * 2], to[1000006 * 2], cnt_e;
inline void Node(const int &u, const int &v) {
  Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v;
}
bool ban[1000006];
int pt[1000006], cnt;
void ser(int now) {
  if (deg[now] || typ[now] != 1) return;
  deg[now] = -1;
  if (!ban[now]) pt[++cnt] = now;
  for (int i = info[now]; i; i = Prev[i]) {
    deg[to[i]]--;
    if (!ban[now]) ban[to[i]] = 1;
    ser(to[i]);
  }
}
int main() {
  read(n), read(m);
  for (int i = 1, u, v; i <= m; i++) read(u), read(v), Node(u, v);
  for (int i = 1; i <= n; i++)
    if (!typ[i]) {
      typ[i] = 1;
      for (int j = info[i]; j; j = Prev[j])
        if (typ[to[j]])
          deg[to[j]]++;
        else
          typ[to[j]] = 2;
    }
  for (int i = 1; i <= n; i++) ser(i);
  printf("%d\n", cnt);
  for (int i = 1; i < cnt; i++) printf("%d ", pt[i]);
  printf("%d\n", pt[cnt]);
}
