#include <bits/stdc++.h>
using namespace std;
int k, head[100005], pnt[200005], nxt[200005], E, ID[200005], val[200005],
    in[200005], m, id[200005], n, ans[200005];
queue<int> q;
void add_edge(int a, int b, int c, int d) {
  pnt[E] = b;
  nxt[E] = head[a];
  val[E] = c;
  ID[E] = d;
  head[a] = E++;
}
bool check(int mid) {
  memset(in, 0, sizeof(in));
  memset(id, 0, sizeof(id));
  for (int i = 1; i <= n; i++) {
    for (int j = head[i]; j != -1; j = nxt[j]) {
      if (val[j] <= mid) continue;
      in[pnt[j]]++;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!in[i]) q.push(i);
  int cnt = 0;
  while (!q.empty()) {
    int xx = q.front();
    q.pop();
    cnt++;
    id[xx] = cnt;
    for (int i = head[xx]; i != -1; i = nxt[i]) {
      if (val[i] <= mid) continue;
      in[pnt[i]]--;
      if (!in[pnt[i]]) q.push(pnt[i]);
    }
  }
  if (cnt != n) return 0;
  k = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = head[i]; j != -1; j = nxt[j]) {
      int v = pnt[j];
      if (val[j] > mid) continue;
      if (id[v] < id[i]) {
        ans[++k] = ID[j];
      }
    }
  }
  return 1;
}
int main() {
  int anss = 0;
  memset(head, -1, sizeof(head));
  cin >> n >> m;
  int r = -1;
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    add_edge(u, v, c, i);
    r = max(r, c);
  }
  int l = 0, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      r = mid - 1;
      anss = mid;
    } else {
      l = mid + 1;
    }
  }
  sort(ans + 1, ans + 1 + k);
  cout << anss << ' ' << k << endl;
  for (int i = 1; i <= k; i++) printf("%d ", ans[i]);
  return 0;
}
