#include <cstdio>
#include <vector>
using namespace std;
vector<int> a[1000];
bool v[1000];
int s, prevv[1000], n, m, x, y;
void dfs(int cur){
	v[cur] = true;
	for (auto e : a[cur]){
		if (e == s){
			prevv[e] = cur;
		}
		if (!v[e]){
			prevv[e] = cur;
			dfs(e);
		}
	}
}
vector<int> optimize(vector<int> p){
	bool b[n];
	fill(b, b + n, false);
	for (int i = 0; i < p.size(); i++) b[p[i]] = true;
	for (int i = 0; i < p.size(); i++){
		int temp = i - 1;
		if (i == 0) temp = p.size() - 1;
		for (auto e : a[p[i]]){
			if (b[e] && e != p[temp]){
				vector<int> np;
				np.emplace_back(p[i]);
				int cur = i;
				while (p[cur] != e){
					cur++;
					if (cur == p.size()) cur = 0;
					np.emplace_back(p[cur]);
				}
				return optimize(np);
			}
		}
	}
	return p;
}
int main(){
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d %d", &x, &y);
		a[x - 1].emplace_back(y - 1);
	}
	for (s = 0; s < n; s++){
		fill(v, v + n, false);
		fill(prevv, prevv + n, -1);
		dfs(s);
		if (prevv[s] != -1){
			vector<int> p;
			p.emplace_back(s);
			int cur = prevv[s];
			while (cur != s){
				p.emplace_back(cur);
				cur = prevv[cur];
			}
			vector<int> bruh = optimize(p);
			printf("%d\n", bruh.size());
			for (int i = 0; i < bruh.size(); i++) printf("%d\n", bruh[i] + 1);
			return 0;
		}
	}
	printf("-1\n");
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll pos=-1;
const ll MAX_N=1001;
vector<bool> visited,finished;
vvll edge(MAX_N);
vll hist;

void dfs(ll now){
  visited[now]=true;
  hist.push_back(now);
  for(auto e:edge[now]){
    if(finished[e])
      continue;

    if(visited[e]&&!finished[e]){
      pos=e;
      return;
    }

    dfs(e);
    if(pos!=-1)
      return;
  }

  hist.pop_back();
  finished[now]=true;
  return;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,m;
  cin>>n>>m;
  REP(i,m){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
  }

  //find cycle
  visited.assign(n,false);
  finished.assign(n,false);
  pos=-1;
  REP(i,n){
    dfs(i);
    if(pos!=-1)
      break;
  }

  if(pos==-1){
    cout<<-1<<endl;
    return 0;
  }

  //restoration cycle
  vll cycle;
  while(true){
    ll t=hist.back();
    hist.pop_back();
    cycle.push_back(t);
    if(pos==t)
      break;
  }

  reverse(ALL(cycle));

  //minimize
  while(true){
    ll nc=cycle.size();
    vll table(n,-1);
    REP(i,nc)table[cycle[i]]=i;

    ll from=-1,to=-1;
    REP(i,nc){
      for(auto e:edge[cycle[i]]){
        if(table[e]!=(i+1)%nc && table[e]!=-1){
          from=i;
          to=table[e];
        }
      }
    }

    if(from==-1)
      break;

    vll ncycle;
    ll cur=to;
    while(true){
      ncycle.push_back(cycle[cur]);
      cur=(cur+1)%nc;
      if(cur==from)
        break;
    }
    ncycle.push_back(cycle[from]);
    cycle=ncycle;
  }

  cout<<cycle.size()<<endl;
  REP(i,cycle.size())cout<<cycle[i]+1<<endl;
}

