#include <bits/stdc++.h>
using namespace std;
const int A = 1e7 + 10;
const int B = 1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  return x * f;
}
struct node {
  int v, nxt, w, kkk;
} e[B];
int cnt, in[B], id[B], cg[B], k = 0, n, m, head[B];
void modify(int u, int v, int w, int kkk) {
  e[++cnt].nxt = head[u];
  e[cnt].w = w;
  e[cnt].v = v;
  e[cnt].kkk = kkk;
  head[u] = cnt;
}
queue<int> q;
bool check(int mid) {
  int kc = 0;
  memset(in, 0, sizeof(in));
  memset(id, 0, sizeof(id));
  for (int i = 1; i <= n; i++) {
    for (int j = head[i]; j; j = e[j].nxt) {
      int v = e[j].v, w = e[j].w;
      if (w <= mid) continue;
      ++in[v];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!in[i]) {
      q.push(i);
    }
  }
  int js = 0;
  while (!q.empty()) {
    int now = q.front();
    id[now] = ++kc;
    js++;
    q.pop();
    for (int i = head[now]; i; i = e[i].nxt) {
      int v = e[i].v, w = e[i].w;
      if (w <= mid) continue;
      --in[v];
      if (!in[v]) q.push(v);
    }
  }
  if (js != n) return 0;
  k = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = head[i]; j; j = e[j].nxt) {
      if (e[j].w > mid) continue;
      int v = e[j].v;
      if (id[v] < id[i]) {
        cg[++k] = e[j].kkk;
      }
    }
  }
  return 1;
}
int main() {
  n = read(), m = read();
  int r = 0;
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read(), w = read();
    modify(u, v, w, i);
    r = max(r, w);
  }
  int l = 0, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      r = mid - 1;
      ans = mid;
    } else
      l = mid + 1;
  }
  sort(cg + 1, cg + k + 1);
  printf("%d %d\n", ans, k);
  for (int i = 1; i <= k; i++) printf("%d ", cg[i]);
}
