def maximal_matching(G): M = set() # Initialize an empty set for the matching sorted_edges = sorted(G.edges, key=lambda e: e.weight) # Sort edges by weight for edge in sorted_edges: u, v = edge.vertices if u not in M and v not in M: M.add(edge) return M n, m = map(int, input().split()) edges = [[x - 1 for x in map(int, input().split())] + [i] for i in range(1, m + 1)] edges.sort(key = lambda e : e[2]) st = set([]) ans = [] for u, v, w in edges: if(u not in st and v not in st): ans.append(w) st.add(u) st.add(v) print(len(ans)) for x in ans: print(x)