//source https://cp-algorithms.com/graph/finding-cycle.html
#include<bits/stdc++.h>
using namespace std;

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}

ll n,m;
vector<vector<ll>>adj;
ll am[1000][1000];
vi color, parent;
ll cycle_start, cycle_end;


bool dfs(int v) {
    color[v] = 1;
    for (int u : adj[v]) {
        if (color[u] == 0) {
            parent[u] = v;
            if (dfs(u))
                return true;
        } else if (color[u] == 1) {
            cycle_end = v;
            cycle_start = u;
            return true;
        }
    }
    color[v] = 2;
    return false;
}

void find_cycle() {
    color.assign(n, 0);
    parent.assign(n, -1);
    cycle_start = -1;

    for (int v = 0; v < n; v++) {
        if (dfs(v))
            break;
    }

    if (cycle_start == -1) {
        cout << "-1" << endl;
    } else {
        vector<int> cycle;
        cycle.push_back(cycle_start);
        for (int v = cycle_end; v != cycle_start; v = parent[v])
            cycle.push_back(v);
        //cycle.push_back(cycle_start);
        reverse(cycle.begin(), cycle.end());
        ll m = cycle.size();
        vi black(m,0);
        cerr<<cycle<<endl;;
        for(int i=0; i<m; i++){
            if(black[i] == 1){
                continue;
            }
            for(int j=1; j<(ll)cycle.size()-2; j++){
                ll cur = (i-j+m)%m;
                if(black[cur]) continue;
                //cout<<cycle[cur]<<" "<<cycle[i]<<endl;
                if(am[cycle[i]][cycle[cur]] == 1){
                    if(cur > i){
                    for(int k=i+1; k<cur; k++){
                        black[k] = 1;
                    }}
                    else {
                        for(int k=i+1; k<m; k++)
                            black[k] = 1;
                        for(int k=0; k<cur; k++){
                            black[k] = 1;
                        }
                    }
                }
            }
        }




        //cout << "Cycle found: ";


        ll count = 0;
        for(int i=0; i<m; i++){
            if(black[i] == 0){
                count++;;
            }
        }
        //cout<<black<<endl;
        if(count < 2){
            cout<<-1<<endl;
            exit(0);
        }
        cout<<count<<"\n";
        for(int i=0; i<m; i++){
            if(black[i] == 0)
                cout<<cycle[i] + 1 <<"\n";
        }
        cout << endl;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    memset(am, 0, sizeof(am[0][0]) * 1000 * 1000);
    adj.reserve(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        adj[a].pb(b);
        am[a][b] = 1;
    }
    find_cycle();


    timer();
    return 0;
}


Measured memory_bytes: 8192