#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct edge {
  int to, next, w;
} e[maxn];
struct node {
  int x, y, w;
} e2[maxn];
int tot = 0;
int head[maxn];
int vis[maxn];
int vis2[maxn];
int deg[maxn];
int n, m;
int cnt;
void add(int x, int y, int w) {
  e[tot].to = y, e[tot].next = head[x], e[tot].w = w, head[x] = tot++;
}
bool bfs() {
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 0) q.push(i);
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = ++cnt;
    for (int i = head[u]; i != -1; i = e[i].next) {
      int v = e[i].to;
      deg[v]--;
      if (deg[v] == 0) q.push(v);
    }
  }
  return cnt == n;
}
bool check(int x) {
  memset(head, -1, sizeof(head));
  memset(vis, 0, sizeof(vis));
  memset(deg, 0, sizeof(deg));
  tot = 0;
  cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (e2[i].w > x) {
      add(e2[i].x, e2[i].y, e2[i].w);
      deg[e2[i].y]++;
    }
  }
  return bfs();
}
int main() {
  scanf("%d%d", &n, &m);
  int r = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e2[i].x, &e2[i].y, &e2[i].w);
    r = max(r, e2[i].w);
  }
  int l = 0;
  int ans = 0, ans2 = 0;
  while (r >= l) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  check(ans);
  for (int i = 1; i <= m; i++) {
    if (e2[i].w <= ans && vis[e2[i].x] > vis[e2[i].y]) ans2++;
  }
  printf("%d %d\n", ans, ans2);
  for (int i = 1; i <= m; i++) {
    if (e2[i].w <= ans && vis[e2[i].x] > vis[e2[i].y]) printf("%d ", i);
  }
  return 0;
}
