#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

#endif




#define mod 1000000007
// グラフ
using Graph = vector<vector<int> >;
 
// 探索
vector<bool> seen, finished;
 
// サイクル復元のための情報
int pos = -1; // サイクル中に含まれる頂点 pos
vector<int> hist; // 訪問履歴
 
void dfs(const Graph &G, int v) {
    seen[v] = true;
    hist.push_back(v);
    for (auto nv : G[v]) {
        // 完全終了した頂点はスルー
        if (finished[nv]) continue;
 
        // サイクルを検出
        if (seen[nv] && !finished[nv]) {
            pos = nv;
            return;
        }
 
        // 再帰的に探索
        dfs(G, nv);
 
        // サイクル検出したならば真っ直ぐに抜けていく
        if (pos != -1) return;
    }
    hist.pop_back();
    finished[v] = true;
}

void solve(){
    int N, M;
    cin >> N >> M;
    Graph G(N);
    rep(i,M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
    }
    
    // 探索
    seen.assign(N, false); finished.assign(N, false);
    pos = -1;
    for (int v = 0; v < N; ++v) {
        pos = -1;
        dfs(G, v);
        if (pos != -1) break;
    }

    // 有向サイクルなし
    if (pos == -1) {
        cout << -1 << endl;
        return ;
    }
    dump(hist);

    // 有向サイクルを復元
    vector<int> cycle;
    while (!hist.empty()) {
        int t = hist.back();
        cycle.push_back(t);
        hist.pop_back();
        if (t == pos) break;
    }
    reverse(cycle.begin(), cycle.end());
    
    dump(cycle);

    vector<int> next(N,-1);
    for(int i=0; i<cycle.size(); i++){
        next[cycle[i]] = cycle[(i+1)%cycle.size()];
    }
    dump(next);

    while(1){
        int from=-1, to=-1;
        for(int v : cycle){
            for(int u : G[v]){
                // uの次がサイクル内に含まれている
                if(find(ALL(cycle),u)!=cycle.end() && u!=next[v]){
                    from = v;
                    to = u;
                    break;
                }
            }
        }
        if(from==-1) break;
        dump(from, to);
        next[from] = to;

        vector<int> newcycle;
        newcycle.push_back(from);
        int v = to;
        while(v!=from){
            newcycle.push_back(v);
            v = next[v];
        }
        
        swap(cycle, newcycle);
        dump(cycle);
    }

    cout << cycle.size() << endl;
    for(int v : cycle)
        cout << v+1 << endl;
    
    
}

signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 384