#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e5 + 100;
int U[maxn], V[maxn], C[maxn];
int VIS;
int N, M;
int vis[maxn];
int tt;
int tempo[maxn];
vector<int> g[maxn];
void dfs(int u) {
  vis[u] = VIS;
  for (int v : g[u]) {
    if (vis[v] == VIS) continue;
    dfs(v);
  }
  tempo[u] = tt++;
}
bool pode(int TANTO) {
  for (int i = 1; i <= N; ++i) g[i].clear();
  for (int i = 1; i <= M; ++i)
    if (C[i] > TANTO) g[U[i]].push_back(V[i]);
  VIS++;
  tt = 1;
  for (int i = 1; i <= N; ++i)
    if (vis[i] != VIS) dfs(i);
  for (int i = 1; i <= M; ++i)
    if (C[i] > TANTO && tempo[U[i]] < tempo[V[i]]) return false;
  return true;
}
int main() {
  cin >> N >> M;
  int l = 0, r = 0;
  for (int i = 1; i <= M; ++i) {
    cin >> U[i] >> V[i] >> C[i];
    r = max(r, C[i]);
  }
  while (r > l) {
    int m = (l + r) >> 1;
    if (pode(m)) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  pode(l);
  vector<int> ans;
  for (int i = 1; i <= M; ++i) {
    if (tempo[U[i]] < tempo[V[i]]) ans.push_back(i);
  }
  cout << l << " " << (int)ans.size() << '\n';
  for (int i : ans) cout << i << ' ';
  cout << '\n';
  return 0;
}
