#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int xb = 0, nxt[maxn], last[maxn], first[maxn], dx[maxn], id[maxn], n, m, x, y,
    z, w[maxn], l, r, mid, ans, cnt = 0, anss[maxn], tpin[maxn], dfn[maxn], hh;
bool vis[maxn];
void build(int x, int y, int z, int u) {
  dx[++xb] = y, w[xb] = z, id[xb] = u;
  if (!first[x])
    first[x] = xb;
  else
    nxt[last[x]] = xb;
  last[x] = xb;
}
bool check(int mid) {
  memset(tpin, 0, sizeof(tpin));
  memset(vis, false, sizeof(vis));
  hh = 0;
  for (int i = 1; i <= n; i++)
    for (int j = first[i]; j; j = nxt[j])
      if (w[j] > mid) tpin[dx[j]]++;
  queue<int> q;
  for (int i = 1; i <= n; i++)
    if (!tpin[i]) q.push(i);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    vis[t] = 1;
    dfn[t] = ++hh;
    for (int i = first[t]; i; i = nxt[i])
      if (w[i] > mid) {
        tpin[dx[i]]--;
        if (!tpin[dx[i]]) q.push(dx[i]);
      }
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) return 0;
  cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = first[i]; j; j = nxt[j])
      if (w[j] <= mid && dfn[dx[j]] < dfn[i]) anss[++cnt] = id[j];
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    build(x, y, z, i);
    r = max(r, z);
  }
  l = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d %d\n", ans, cnt);
  sort(anss + 1, anss + cnt + 1);
  for (int i = 1; i <= cnt; i++) printf("%d ", anss[i]);
  return 0;
}
