#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, maxm = 1e5 + 10, INF = 0x3f3f3f3f;
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
int n, m;
int X[maxm], Y[maxm], C[maxm], in[maxn];
int Head[maxn], V[maxm], Next[maxm], tot;
int vis[maxn], tim[maxn], ret[maxm], cnt;
queue<int> q;
void Add(int u, int v) {
  V[++tot] = v;
  Next[tot] = Head[u];
  Head[u] = tot;
}
bool check(int lim) {
  for (int i = 1; i <= n; i++) {
    Head[i] = 0;
    in[i] = 0;
  }
  tot = cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (C[i] > lim) {
      Add(X[i], Y[i]);
      in[Y[i]]++;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!in[i]) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[++cnt] = u;
    for (int i = Head[u]; i; i = Next[i]) {
      int v = V[i];
      in[v]--;
      if (!in[v]) {
        q.push(v);
      }
    }
  }
  return cnt == n;
}
int main() {
  int l, r, mid, ans;
  read(n);
  read(m);
  l = 0;
  r = 0;
  for (int i = 1; i <= m; i++) {
    read(X[i]);
    read(Y[i]);
    read(C[i]);
    r = max(r, C[i]);
  }
  while (l <= r) {
    mid = l + r >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  check(ans);
  for (int i = 1; i <= n; i++) {
    tim[vis[i]] = i;
  }
  cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (tim[X[i]] > tim[Y[i]]) {
      ret[++cnt] = i;
    }
  }
  printf("%d %d\n", ans, cnt);
  for (int i = 1; i <= cnt; i++) printf("%d ", ret[i]);
  return 0;
}
