#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int INF = 1e9 + 7;
struct edge {
  int from;
  int to;
  int cost;
} edges[maxn];
vector<int> G[maxn];
vector<int> che;
int topo[maxn];
int ind[maxn];
int n, m;
int id;
bool check(int mid) {
  id = 0;
  memset(ind, 0, sizeof(ind));
  for (int i = 1; i <= n; ++i) G[i].clear();
  for (int i = 1; i <= m; ++i) {
    if (edges[i].cost > mid) {
      G[edges[i].from].push_back(edges[i].to);
      ind[edges[i].to]++;
    }
  }
  queue<int> q;
  for (int i = 1; i <= n; ++i) {
    if (ind[i] == 0) {
      q.push(i);
      topo[i] = id++;
    }
  }
  while (!q.empty()) {
    int nowp = q.front();
    q.pop();
    for (int i = 0; i < G[nowp].size(); ++i) {
      int to = G[nowp][i];
      ind[to]--;
      if (ind[to] == 0) {
        topo[to] = id++;
        q.push(to);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (ind[i]) return false;
  }
  return true;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> edges[i].from >> edges[i].to >> edges[i].cost;
  }
  int l = 0, r = INF;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  check(ans);
  for (int i = 1; i <= m; ++i) {
    if (topo[edges[i].from] > topo[edges[i].to]) {
      che.push_back(i);
    }
  }
  cout << ans << " " << che.size() << endl;
  for (int i = 0; i < che.size(); ++i) {
    if (i) cout << " ";
    cout << che[i];
  }
  cout << endl;
  return 0;
}
