#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
struct lenka {
  int x, y, z;
} ed[MAX];
vector<int> e[MAX];
vector<int> QAQ;
int top[MAX], in[MAX];
int n, m;
int check(int QWQ) {
  for (int i = 1; i <= n; i++) e[i].clear();
  memset(in, 0, sizeof in);
  for (int i = 1; i <= m; i++) {
    if (ed[i].z > QWQ) {
      e[ed[i].x].push_back(ed[i].y);
      ++in[ed[i].y];
    }
  }
  queue<int> p;
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (in[i] == 0) p.push(i), top[i] = ++cnt;
  while (!p.empty()) {
    int now = p.front();
    p.pop();
    for (int i = 0; i < e[now].size(); i++) {
      int nex = e[now][i];
      in[nex]--;
      if (in[nex] == 0) {
        p.push(nex);
        top[nex] = ++cnt;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (in[i]) return 0;
  QAQ.clear();
  for (int i = 1; i <= m; i++)
    if (ed[i].z <= QWQ && top[ed[i].y] < top[ed[i].x]) QAQ.push_back(i);
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &ed[i].x, &ed[i].y, &ed[i].z);
  int l = 0, r = 1e9, ans = 0;
  while (r >= l) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  check(ans);
  printf("%d %d\n", ans, QAQ.size());
  for (int i = 0; i < QAQ.size(); i++) cout << QAQ[i] << " ";
  return 0;
}
