#include <bits/stdc++.h>
using namespace std;
inline void rd(int &x) {
  x = 0;
  char ch = 0;
  int w = 0;
  while (!isdigit(ch)) ch = getchar(), w |= ch == '-';
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
}
int s[100005], top;
int n, m, l, r, now;
int head[100005], cnt, v[100005], d[100005], du[100005];
struct nd {
  int nxt, to, v, x;
} e[100005];
inline void add(int x, int y, int v) {
  e[++cnt] = (nd){head[x], y, v, x};
  head[x] = cnt;
}
void work(int lim) {
  queue<int> q;
  memset(d, 0, sizeof d);
  memset(du, 0, sizeof du);
  for (int x = 1; x <= n; x++)
    for (int y, i = head[x]; (y = e[i].to); i = e[i].nxt)
      if (e[i].v > lim) du[y]++;
  for (int i = 1; i <= n; i++)
    if (!du[i]) q.push(i);
  int tot = 0;
  while (q.size()) {
    int x = q.front();
    q.pop();
    d[x] = ++tot;
    for (int y, i = head[x]; (y = e[i].to); i = e[i].nxt)
      if (e[i].v > lim) {
        if (--du[y] == 0) q.push(y);
      }
  }
  top = 0;
  for (int x = 1; x <= n; x++)
    for (int y, i = head[x]; (y = e[i].to); i = e[i].nxt)
      if (e[i].v <= lim and d[x] > d[y]) s[++top] = i;
}
bool ok(int lim) {
  work(lim);
  for (int i = 1; i <= n; i++)
    if (du[i]) return 0;
  return 1;
}
signed main() {
  rd(n);
  rd(m);
  for (int x, y, v, i = 1; i <= m; i++)
    rd(x), rd(y), rd(v), add(x, y, v), r = max(r, v);
  while (l < r) {
    int mid = (l + r) >> 1;
    ok(mid) ? r = mid : l = mid + 1;
  }
  work(l);
  printf("%d %d\n", l, top);
  for (int i = 1; i <= top; i++) printf("%d ", s[i]);
}
