#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 20;
struct hedge {
  int v, d;
};
struct edge {
  int u, v;
};
enum { WHITE, GRAY, BLACK };
int N, M, D;
vector<hedge> G[MAXN];
int color[MAXN], Index[MAXN];
vector<int> ts;
vector<edge> E;
bool cycle(int v) {
  color[v] = GRAY;
  for (auto w : G[v])
    if (w.d > D) {
      if (color[w.v] == GRAY)
        return true;
      else if (color[w.v] == WHITE and cycle(w.v))
        return true;
    }
  color[v] = BLACK;
  return false;
}
bool can(int m) {
  memset(color, 0, sizeof color);
  D = m;
  for (int i = 0; i < int(N); i++)
    if (not color[i])
      if (cycle(i)) return false;
  return true;
}
void toposort(int v) {
  color[v] = BLACK;
  for (auto w : G[v])
    if (w.d > D and not color[w.v]) toposort(w.v);
  ts.push_back(v);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;
  for (int i = 0; i < int(M); i++) {
    int u, v, c;
    cin >> u >> v >> c;
    --u, --v;
    G[u].push_back({v, c});
    E.push_back({u, v});
  }
  long long a = -1, b = 1e9;
  while (b - a > 1) {
    long long m = (a + b) / 2;
    if (can(m))
      b = m;
    else
      a = m;
  }
  D = b;
  memset(color, 0, sizeof color);
  for (int i = 0; i < int(N); i++)
    if (not color[i]) toposort(i);
  for (int i = 0; i < int(N); i++) Index[ts[i]] = i;
  int K = 0;
  for (int i = 0; i < int(M); i++)
    if (Index[E[i].u] < Index[E[i].v]) ++K;
  cout << D << ' ' << K << '\n';
  for (int i = 0; i < int(M); i++)
    if (Index[E[i].u] < Index[E[i].v]) cout << i + 1 << ' ';
  cout << endl;
  return 0;
}
