#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = N;
int n, m, in[N];
struct Edge {
  int u, v, c, id;
  bool operator<(const Edge &o) const { return c > o.c; }
};
vector<Edge> es;
vector<int> g[N];
vector<int> toposort(int mid) {
  for (int x = (0), qwerty = (n); x < qwerty; x++) g[x].clear(), in[x] = 0;
  for (int x = (0), qwerty = (mid); x < qwerty; x++) {
    g[es[x].u].push_back(es[x].v);
    in[es[x].v]++;
  }
  queue<int> q;
  for (int x = (0), qwerty = (n); x < qwerty; x++)
    if (!in[x]) q.push(x);
  vector<int> ans;
  while (int((q).size())) {
    int u = q.front();
    q.pop();
    ans.push_back(u);
    for (int v : g[u]) {
      in[v]--;
      if (!in[v]) q.push(v);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int x = (0), qwerty = (m); x < qwerty; x++) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    es.push_back({u, v, c, x});
  }
  sort((es).begin(), (es).end());
  int lw = 0, hg = m, ans = 0, mid;
  while (hg >= lw) {
    mid = (hg + lw) / 2;
    if (int((toposort(mid)).size()) == n)
      ans = max(ans, mid), lw = mid + 1;
    else
      hg = mid - 1;
  }
  if (ans == m)
    cout << "0 0\n";
  else {
    vector<int> e;
    vector<int> ts = toposort(ans), rts(n);
    for (int x = (0), qwerty = (n); x < qwerty; x++) rts[ts[x]] = x;
    for (int x = (0), qwerty = (m); x < qwerty; x++)
      if (rts[es[x].u] > rts[es[x].v]) e.push_back(es[x].id + 1);
    sort((e).begin(), (e).end());
    cout << es[ans].c << " " << int((e).size()) << "\n";
    for (int x = (0), qwerty = (int((e).size())); x < qwerty; x++)
      cout << e[x] << " \n"[int((e).size()) - 1 == x];
  }
}
