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

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

    @property bool root() {
        return parent is null;
    }

    private int _rank = 0;
    @property int rank() {
        if (_rank > 0) return _rank;
        _rank = (parent ? parent.rank + 1 : 1);
        return _rank;
    }

    Node common_ancestor(Node x) {
        if (this == x) return this;
        if (rank > x.rank) {
            return parent.common_ancestor(x);
        } else if (rank == x.rank) {
            return parent.common_ancestor(x.parent);
        } else {
            return common_ancestor(x.parent);
        }
    }
}

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].parent = employees[a];
    }

    foreach (i; 1 .. n + 1) {
        if (!employees[i].parent) {
            employees[i].parent = 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);

    Node the_boss = max_ranker.reduce!("a.common_ancestor(b)");

    Node tmp = the_boss;
    bool[] ok = new bool[n + 1];
    while (tmp) {
        ok[tmp.index] = true;
        tmp = tmp.parent;
    }

    int[] ans;
    foreach (i; 0 .. m) {
        int a = as[i];
        int b = bs[i];
        if (ok[b]) ans ~= i + 1;
        /*if (employees[a].check(employees[b])) {
            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);
    }*/
}