#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10;
const long long mxn = 1e13 + 10;
const long long mo = 1e9;
long long n, m, x, y, i, j, k, q, js = 0, jj = 0;
long long pm(long long a, long long k) {
  long long res = 1;
  a %= mo;
  while (k) {
    if (k & 1) res = res * a % mo;
    a = a * a % mo;
    k >>= 1;
  }
  return res;
}
struct node {
  long long u, v, c;
} nd[100010];
long long pos[100010], da[100010];
vector<long long> v[100010];
void dfs(long long x) {
  if (pos[x]) return;
  pos[x] = 1;
  for (auto j : v[x]) {
    dfs(j);
  }
  pos[x] = ++js;
  return;
}
bool ck(long long x) {
  jj = 0;
  js = 0;
  for (long long i = 1; i <= n; i++) {
    v[i].clear();
    pos[i] = 0;
  }
  for (long long i = 0; i < m; i++) {
    if (nd[i].c > x) v[nd[i].u].push_back(nd[i].v);
  }
  for (long long i = 1; i <= n; i++) dfs(i);
  for (long long i = 0; i < m; i++) {
    if (pos[nd[i].u] < pos[nd[i].v]) {
      if (nd[i].c > x) return 0;
      da[jj++] = i + 1;
    }
  }
  return 1;
}
int main() {
  long long t, tt, tot = 1, pd = 0, x, y, zd = 0, ans = 0, js = 0;
  scanf("%lld %lld", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%lld %lld %lld", &nd[i].u, &nd[i].v, &nd[i].c);
  }
  long long l = 0, r = 1e9 + 1;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (ck(mid))
      r = mid;
    else
      l = mid + 1;
  }
  ck(l);
  printf("%lld %lld\n", l, jj);
  for (i = 0; i < jj; i++) {
    printf("%lld ", da[i]);
  }
  return 0;
}
