#include <iostream>
#include <cstdlib>
#include<vector>
#include<unordered_map>
#include<unordered_set>

int n,m;
std::unordered_map<int,std::vector<int>> v;
void check(int k,std::unordered_set<int> const& memo){
    for(auto x: v[k]){
        if(memo.count(x)){
            std::cout << memo.size()<<"\n";
            for(auto r:memo)
                std::cout << r <<"\n";
            std::exit(0);
        }
        auto t = memo;
        t.emplace(x);
        check(x,t);
    }
}


int main()
{


    std::cin>>n>>m;
    for(int i=0;i<m;++i)
    {
        int a,b;
        std::cin>>a>>b;
        v[a].push_back(b);
    }
    
    
    for(int i=1;i<=n;++i)
    {
        check(i,{i});
    }
    std::cout<<-1;
}



