#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
const double eps = 1e-6;
inline long long rd() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int n, m;
struct node {
  int from, to, len;
} aa[maxn];
vector<pair<int, int> > ve[maxn];
int deep[maxn], cc[maxn], cnt;
vector<int> res;
bool check(int x) {
  memset(deep, 0, sizeof deep);
  memset(cc, 0, sizeof cc);
  for (int i = 1; i <= n; i++) ve[i].clear();
  cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (aa[i].len > x) {
      deep[aa[i].to]++;
      ve[aa[i].from].push_back(pair<int, int>(aa[i].to, aa[i].len));
    }
  }
  queue<int> qu;
  for (int i = 1; i <= n; i++)
    if (!deep[i]) qu.push(i);
  while (qu.size()) {
    int y = qu.front();
    cc[y] = ++cnt;
    qu.pop();
    for (int i = 0; i < ve[y].size(); i++) {
      deep[ve[y][i].first]--;
      if (!deep[ve[y][i].first]) qu.push(ve[y][i].first);
    }
  }
  return cnt == n;
}
int main() {
  n = rd(), m = rd();
  for (int i = 1; i <= m; i++) {
    aa[i].from = rd(), aa[i].to = rd(), aa[i].len = rd();
  }
  int l = 0, r = inf;
  int ans = 0;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  check(ans);
  for (int i = 1; i <= m; i++) {
    if (aa[i].len <= ans && cc[aa[i].from] > cc[aa[i].to]) res.push_back(i);
  }
  printf("%d %d\n", ans, res.size());
  for (int i = 0; i < res.size(); i++)
    printf("%d%c", res[i], i == res.size() - 1 ? '\n' : ' ');
}
