#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long MAX = 1e6 + 1;
long long n, m;
vector<long long> d[MAX];
long long res[MAX];
long long deg[MAX];
long long nie[MAX];
void take(long long v) {
  res[v] = 1;
  for (long long el : d[v]) {
    if (res[el]) {
      deg[el]++;
    } else {
      res[el] = 2;
    }
  }
}
vector<long long> out;
void dfs(long long v) {
  if (res[v] != 1 || deg[v] != 0) return;
  deg[v] = -1;
  if (!nie[v]) out.push_back(v);
  for (long long el : d[v]) {
    if (!nie[v]) {
      nie[el] = 1;
    }
    deg[el]--;
    dfs(el);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> n >> m;
  for (long long i = (0); i <= ((long long)(m)-1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    d[a].push_back(b);
  }
  for (long long i = (0); i <= ((long long)(n)-1); i++)
    if (res[i] == 0) {
      take(i);
    }
  for (long long i = (0); i <= ((long long)(n)-1); i++) dfs(i);
  cout << ((long long)(out).size()) << "\n";
  for (long long el : out) {
    cout << el + 1 << " ";
  }
  cout << "\n";
}
