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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct Node{
    int id, v;
    bool done = false;
    Node(int id, int v=0): id(id), v(v) {}
    Node(): id(0), v(0) {}

    bool operator==(const Node& x) { return v == x.v; }
    bool operator!=(const Node& x) { return v != x.v; }
    bool operator<(const Node& x) { return v < x.v; }
    bool operator>(const Node& x) { return v > x.v; }
    bool operator<=(const Node& x) { return v <= x.v; }
    bool operator>=(const Node& x) { return v >= x.v; }

    bool comp(Node node){
        return v < node.v;
    }
};

struct Edge{
    int from, to, cost, id;
    Edge(int from, int to, int cost=1, int id=-1): from(from), to(to), cost(cost), id(id) {}

    bool comp(Edge e){
        return cost < e.cost;
    }
};

struct Graph{
    int N;
    vector<vector<Edge>> adj;
    vector<Node> node;

    Graph(int N): N(N) {
        adj.resize(N, vector<Edge>());
        node.resize(N);
        for(int i=0; i<N; ++i) node[i].id = i;
    }

    Graph() {}

    void add_edge(int i, int j, int cost=1, int id=-1){
        Edge e(i, j, cost, id);
        adj[i].emplace_back(e);
    }

    vector<Edge> get_adj(Node node){
        return adj[node.id];
    }

    void assign(int n){
        N = n;
        adj.assign(N, vector<Edge>());
        node.assign(N, Node());
        for(int i=0; i<N; ++i) node[i].id = i;
    }
};

Graph G;

VI usev, usee, done;
int status = 0;
VVI eid;

bool dfs(int to, int from){
    if(G.node[to].done && done[to]) return false;
    if(G.node[to].done && done[to]==0){
        usev[to] = 1; usev[from] = 1;
        usee[eid[from][to]] = 1;
        return true;
    }

    G.node[to].done = true;
    for(Edge& edge : G.adj[to]){
        if(dfs(edge.to, edge.from)){
            if(status == 1) return true;
            usee[eid[from][to]] = 1;
            if(usev[from] == 0) usev[from] = 1;
            else status = 1;
            return true;
        }
    }

    done[to] = 1;
    return false;
}

int main(void){
    int N,M; cin >> N >> M;
    G.assign(N);
    usev.assign(N, 0); usee.assign(M, 0);
    done.assign(N,0);
    eid.assign(M,VI(M,0));
    REP(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        G.add_edge(a,b,1,i);
        eid[a][b] = i;
    }

    bool flag = true;
    REP(i,N){
        if(dfs(i,i) == true){
            flag = false;
            break;
        }
    }

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

    VI ans;
    while(1){
        bool flag = true;
        int from, stop;
        VI newv(N,0), newe(M,0);
        REP(i,N){
            if(usev[i] == 0) continue;
            bool flag2 = false;
            for(Edge& edge : G.adj[i]){
                if(usev[edge.to] == 1 && usee[eid[edge.from][edge.to]] == 0){
                    newv[edge.from] = 1;
                    newv[edge.to] = 1;
                    newe[eid[edge.from][edge.to]] = 1;
                    from = edge.to;
                    stop = edge.from;
                    flag = false;
                    flag2 = true;
                    break;
                }
            }
            if(flag2) break;
        }
        if(flag){
            REP(i,N) if(usev[i]) ans.push_back(i+1);
            break;
        }

        while(from != stop){
            for(Edge& e : G.adj[from]){
                if(usee[eid[e.from][e.to]] == 1){
                    from = e.to;
                    newv[e.to] = 1;
                    newe[eid[e.from][e.to]] = 1;
                    break;
                }
            }
        }
        swap(usev, newv); swap(usee, newe);
    }

    int K = ans.size();
    cout << K << endl;
    REP(i,K) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 16128