#include <bits/stdc++.h>
using namespace std;
int n, m;
int res[100010], k = 0;
struct edge {
  int id, v, w, next;
} e[100010];
int head[100010], cnt = 0;
void adde(int u, int v, int w, int id) {
  e[cnt].id = id;
  e[cnt].v = v;
  e[cnt].w = w;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
int ind[100010];
queue<int> q;
int lev[100010];
int tl;
bool check(int lim) {
  memset(ind, 0, sizeof ind);
  memset(lev, 0, sizeof lev);
  tl = 0;
  while (!q.empty()) q.pop();
  for (int i = 0; i < cnt; ++i)
    if (e[i].w > lim) ++ind[e[i].v];
  for (int i = 1; i <= n; ++i)
    if (ind[i] == 0) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    lev[u] = tl++;
    for (int i = head[u], v, w; ~i; i = e[i].next) {
      v = e[i].v;
      w = e[i].w;
      if (w <= lim) continue;
      --ind[v];
      if (ind[v] == 0) {
        q.push(v);
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    if (ind[i]) return false;
  return true;
}
int main() {
  memset(head, -1, sizeof head);
  scanf("%d%d", &n, &m);
  int L = 0, R = 0, mid, ans;
  for (int i = 1, u, v, w; i <= m; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    adde(u, v, w, i);
    R = max(R, w);
  }
  ++R;
  while (L < R) {
    mid = (L + R) >> 1;
    if (check(mid)) {
      ans = R = mid;
    } else {
      L = mid + 1;
    }
  }
  check(ans);
  for (int u = 1; u <= n; ++u) {
    for (int i = head[u], v, w; ~i; i = e[i].next) {
      v = e[i].v;
      w = e[i].w;
      if (w > ans) continue;
      if (lev[u] > lev[v]) res[++k] = e[i].id;
    }
  }
  printf("%d %d\n", ans, k);
  for (int i = 1; i <= k; ++i) printf("%d%c", res[i], (i == k ? '\n' : ' '));
  return 0;
}
