import std.stdio;
import std.conv;
import std.array;
import std.algorithm;

const bool DEBUG = false;

class Node {
    int index;
    Node[] parents;
    Node[] children;
    this(int index) {
        this.index = index;
    }

    @property bool root() {
        return parents.empty;
    }

    private int _rank = 0;
    @property int rank() {
        if (_rank > 0) return _rank;
        foreach (parent; parents) {
            _rank = max(_rank, parent.rank);
        }
        _rank++;
        return _rank;
    }
}

void main() {
    int n, m; readf("%d %d\n", &n, &m);
    Node[] employees = new Node[n + 1];
    foreach (i; 0 .. n + 1) {
        employees[i] = new Node(i);
    }

    int[] as = new int[m];
    int[] bs = new int[m];
    foreach (i; 0 .. m) {
        int a, b; readf("%d %d\n", &a, &b);
        as[i] = a; bs[i]  = b;
        employees[a].children ~= employees[b];
        employees[b].parents  ~= employees[a];
    }

    foreach (i; 1 .. n + 1) {
        if (employees[i].parents.empty) {
            employees[i].parents  ~= employees[0];
            employees[0].children ~= employees[i];
        }
    }

    int max_rank = employees.map!"a.rank".reduce!max;
    auto max_ranker = employees.filter!((a) => a.rank == max_rank).array;

    static if (DEBUG) writeln("max_ranker: ", max_ranker.map!"a.index");

    int[] count = new int[n + 1];
    void f(Node x) {
        count[x.index]++;
        auto true_parents = x.parents.filter!((a) => a.rank + 1 == x.rank).array;
        if (true_parents.length > 1) return;
        foreach (parent; true_parents) {
            f(parent);
        }
    }
    foreach (r; max_ranker) {
        f(r);
    }

    static if (DEBUG) { 
        writeln("parents: ", employees.map!"a.parents.map!((x) => x.index)".array);
        writeln("rank: ", employees.map!"a.rank".array);
        writeln("count: ", count);
    }

    int[] ans;
    foreach (i; 0 .. m) {
        int a = as[i];
        int b = bs[i];
        //if (employees[a].rank + 1 == employees[b].rank && count[b] == max_ranker.length) ans ~= i + 1;
        if (employees[a].rank + 1 == employees[b].rank && 
            count[a] == max_ranker.length && 
            count[b] == max_ranker.length) 
            ans ~= i + 1;
    }

    (ans.length ? ans.map!(to!string).join("\n") : "-1").writeln;

    /*foreach (i; 0 .. n + 1) {
        writeln("Emp ", i, ",rank: ", employees[i].rank);
    }*/
}