#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

// definition of class edge
class edge{
public:
  long long int to, cost;
  
  edge(long long int t, long long int c){
    to = t;
    cost = c;
  }
  
  bool operator < (const class edge &another) const{
    return cost < another.cost;
  }
  
  bool operator > (const class edge &another) const{
    return cost > another.cost;
    }
};

class path{
public:
  long long int to, dist;
  
  path(long long int t, long long int d){
    to = t;
    dist = d;
  }
  
  path(){
    to = 0;
    dist = 0;
  }
  
  bool operator < (const class path &another) const{
    return dist < another.dist;
  }
  
  bool operator > (const class path &another) const{
    return dist > another.dist;
  }
};

class path2{
public:
  long long int from, to, dist;
  
  path2(long long int f, long long int t, long long int d){
    from = f;
    to = t;
    dist = d;
  }
  
  path2(){
    from = 0;
    to = 0;
    dist = 0;
  }
  
  bool operator < (const class path2 &another) const{
    return dist < another.dist;
  }
  
  bool operator > (const class path2 &another) const{
    return dist > another.dist;
  }
};

int Dijkstra(std::vector<std::vector<edge> > &G, /*long long int E, */long long int V, std::vector<long long int> &distance, long long int start);
int Dijkstra2(std::vector<std::vector<edge> > &G, /*long long int E, */long long int V, std::vector<long long int> &distance, std::vector<long long int> &from, long long int start);


int main(){
  
  // read problem
  long long int N, M, a, b, tmp;
  scanf("%lld%lld", &N, &M);
  
  std::vector<std::vector<edge> > G(N+1);
  std::vector<std::vector<long long int> > Gto(N);
  for(long long int i = 0; i < M; i++){
    scanf("%lld%lld", &a, &b);
    G[a-1].push_back(edge(b-1, 1));
    Gto[b-1].push_back(a-1);
  }
  
  //std::cerr << "Greaph is read:\nstart calculation\n\n";
  
  // solve problem
  
  long long int L = 100000;
  std::vector<long long int> loop;
  std::vector<long long int> distance(N+1), From(N+1);

  for(long long int i = 0; i < N; i++){
    //std::cerr << "i = " << i << std::endl;
    // update G
    for(long long int j = 0; j < Gto[i].size(); j++){
      G[Gto[i][j]].push_back(edge(N,1));
    }
    //std::cerr << "G is updated\n" << std::endl;
    // Dijkstra
    Dijkstra2(G, N+1, distance, From, i);
    //std::cerr << "Dijkstra is finished\n" << std::endl;
    // update answer
    if(distance[N] < L && distance[N] > 0){
      L = distance[N];
      //std::cerr << "L = " << L << std::endl;
      loop.clear();
      tmp = N;
      while(From[tmp]>=0){
        tmp = From[tmp];
        loop.push_back(tmp);
      }
      //loop.push_back(i);
    }
    //std::cerr << "Answer is updated\n" << std::endl;
    // restore G
    for(long long int j = 0; j < Gto[i].size(); j++){
      G[Gto[i][j]].erase(G[Gto[i][j]].end()-1);
    }
    //std::cerr << "G is restored\n" << std::endl;

  }

  
  if (L == 100000){
    std::cout << -1 << std::endl;
  }
  else{
    std::cout << loop.size() << std::endl;
    for(long long int i = loop.size()-1; i >= 0; i--){
      std::cout << loop[i]+1 << std::endl;
    }
  }
  
  
  return 0;
  
}

int Dijkstra(std::vector<std::vector<edge> > &G, /*long long int E, */long long int V, std::vector<long long int> &distance, long long int start){
  
  // preparation of path queue
  std::priority_queue<path, std::vector<path>, std::greater<path> > path_que;
  // initialize distance
  for(long long int i = 0; i < V; i++){
    distance[i] = -1;
  }
  
  // Dijkstra method
  path path_tmp;
  // starting point
  distance[start] = 0;
  for(long long int i = 0; i < G[start].size(); i++){
    path_que.push(path(G[start][i].to, G[start][i].cost));
  }
  
  // following points
  while(!path_que.empty()){
    // pop shortest path to look into
    path_tmp = path_que.top();
    path_que.pop();
    // update distance list and push newly obtained paths
    if(distance[path_tmp.to] < 0){
      distance[path_tmp.to] = path_tmp.dist;
      for(long long int i = 0; i < G[path_tmp.to].size(); i++){
        path_que.push(path(G[path_tmp.to][i].to, path_tmp.dist + G[path_tmp.to][i].cost));
      }
    }
  }
  
  return 0;
}

int Dijkstra2(std::vector<std::vector<edge> > &G, /*long long int E, */long long int V, std::vector<long long int> &distance, std::vector<long long int> &From, long long int start){
  // preparation of path queue
  std::priority_queue<path2, std::vector<path2>, std::greater<path2> > path_que;
  // initialize distance
  for(long long int i = 0; i < V; i++){
    distance[i] = -1;
    From[i] = -1;
  }
  
  // Dijkstra method
  path2 path_tmp;
  // starting point
  distance[start] = 0;
  for(long long int i = 0; i < G[start].size(); i++){
    path_que.push(path2(start, G[start][i].to, G[start][i].cost));
  }
  
  // following points
  while(!path_que.empty()){
    // pop shortest path to look into
    path_tmp = path_que.top();
    path_que.pop();
    // update distance list and push newly obtained paths
    if(distance[path_tmp.to] < 0){
      distance[path_tmp.to] = path_tmp.dist;
      From[path_tmp.to] = path_tmp.from;
      for(long long int i = 0; i < G[path_tmp.to].size(); i++){
        path_que.push(path2(path_tmp.to, G[path_tmp.to][i].to, path_tmp.dist + G[path_tmp.to][i].cost));
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 384