#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, c;
vector<pair<pair<int, int>, pair<int, int> > > edge;
int visited[100000 + 5];
vector<int> v[100000 + 5];
int num[100000 + 5], val;
bool dfs(int cur) {
  if (visited[cur] == 1)
    return false;
  else if (visited[cur] == 2)
    return true;
  visited[cur] = 1;
  bool res = true;
  for (int i = 0; i < v[cur].size(); i++) {
    res &= dfs(v[cur][i]);
  }
  visited[cur] = 2;
  num[cur] = val;
  val++;
  return res;
}
bool calc(int x) {
  for (int i = 0; i < n; i++) {
    visited[i] = 0;
    v[i].clear();
    num[i] = 0;
  }
  for (int i = 0; i < edge.size(); i++) {
    if (edge[i].first.first > x) {
      int a = edge[i].second.first;
      int b = edge[i].second.second;
      v[a].push_back(b);
    }
  }
  val = 1;
  bool res = true;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      res &= dfs(i);
    }
  }
  return res;
}
int cari(int x, int y) {
  if (x >= y) return x;
  int mid = (x + y) >> 1;
  if (calc(mid)) {
    return cari(x, mid);
  } else {
    return cari(mid + 1, y);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    edge.push_back(make_pair(make_pair(c, i), make_pair(a, b)));
  }
  sort(edge.begin(), edge.end());
  int val = cari(0, 1000000007);
  calc(val);
  vector<int> res;
  for (int i = 0; i < n; i++) {
    if (num[i] == 0) {
      num[i] = val;
      val++;
    }
  }
  for (int i = 0; i < edge.size(); i++) {
    int a = edge[i].second.first;
    int b = edge[i].second.second;
    if (edge[i].first.first <= val and num[a] < num[b]) {
      res.push_back(edge[i].first.second + 1);
    }
  }
  printf("%d %d\n", val, res.size());
  for (int i = 0; i < res.size(); i++) {
    printf("%d", res[i]);
    if (i == res.size() - 1)
      printf("\n");
    else
      printf(" ");
  }
}
