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

const bool DEBUG = true;

class Node {
    string name;
    Node[] parents;
    Node[] children;

    static Node birth, end;

    static this() {
        birth = new Node;
        end = new Node;
    }

    private this() {}

    this(string name) {
        this.name = name;
        birth.children ~= this;
        parents = [birth];
        end.parents ~= this;
        children = [end];
    }

    private int _fromBirth = -1;
    @property int fromBirth() {
        if (_fromBirth >= 0) return _fromBirth;
        int dist = 0;
        foreach (p; parents) {
            dist = max(dist, p.fromBirth + 1);
        }
        return _fromBirth = dist;
    }

    private int _toEnd = -1;
    @property int toEnd() {
        if (_toEnd >= 0) return _toEnd;
        int dist = 0;
        foreach (c; children) {
            dist = max(dist, c.toEnd + 1);
        }
        return _toEnd = dist;
    }

    static int longest() {
        return birth.toEnd;
    }
}

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

    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];
    }

    int[] list;
    int[] fromFlag = new int[n + 1];
    int[] toFlag   = new int[n + 1];
    foreach (i; 0 .. m) {
        auto a = employees[as[i]];
        auto b = employees[bs[i]];
        if (a.fromBirth + b.toEnd + 1 == Node.longest) {
            fromFlag[as[i]]++;
            toFlag[bs[i]]++;
            list ~= i;
        }
    }

    int[] ans;
    foreach (i; list) {
        if (fromFlag[as[i]] > 1 || toFlag[bs[i]] > 1) continue;
        ans ~= i + 1;
    }

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