#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const long long N = 1e5 + 10;
struct Edge {
  long long u, v, c, i;
};
bool comp(Edge a, Edge b) { return a.c < b.c; }
Edge e[N];
vector<long long> g[N];
char used[N];
long long ord[N];
bool fl = false;
void dfs(long long v) {
  used[v] = 1;
  for (long long to : g[v]) {
    if (used[to] == 0) {
      dfs(to);
    } else if (used[to] == 1) {
      fl = true;
    }
  }
  used[v] = 2;
}
long long tim = 0;
void dfs2(long long v) {
  used[v] = 1;
  for (long long to : g[v]) {
    if (!used[to]) {
      dfs2(to);
    }
  }
  ord[v] = tim++;
}
signed main() {
  fast();
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> e[i].u >> e[i].v >> e[i].c;
    e[i].u--;
    e[i].v--;
    e[i].i = i;
  }
  sort(e, e + m, comp);
  long long l = -1, r = m - 1;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (l == -1 && r == 0) mid = -1;
    for (long long i = 0; i < n; i++) {
      g[i].clear();
      used[i] = 0;
    }
    for (long long i = mid + 1; i < m; i++) {
      g[e[i].u].push_back(e[i].v);
    }
    fl = false;
    for (long long i = 0; i < n; i++) {
      if (used[i] == 0) {
        dfs(i);
      }
    }
    if (fl) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  for (long long i = 0; i < n; i++) {
    g[i].clear();
    used[i] = 0;
  }
  for (long long i = l + 1; i < m; i++) {
    g[e[i].u].push_back(e[i].v);
  }
  for (long long i = 0; i < n; i++) {
    if (used[i] == 0) {
      dfs2(i);
    }
  }
  vector<long long> answ;
  long long cc = 0;
  for (long long i = 0; i <= l; i++) {
    if (ord[e[i].v] > ord[e[i].u]) {
      answ.push_back(e[i].i + 1);
      cc = max(cc, e[i].c);
    }
  }
  cout << cc << ' ' << answ.size() << '\n';
  sort(answ.begin(), answ.end());
  for (long long i : answ) {
    cout << i << ' ';
  }
  return 0;
}
