#include <bits/stdc++.h>
using namespace std;
bool vis[100005];
set<int> s;
vector<pair<int, int> > vec[1000005];
bool flg;
int u, v, w, n, m;
pair<pair<int, int>, int> ed[100005];
vector<int> ans;
int pos[100005];
void dfs(int nod, int x) {
  vis[nod] = 1;
  s.insert(nod);
  for (auto i : vec[nod]) {
    if (i.second > x) {
      if (s.find(i.first) != s.end()) flg = 0;
      if (!vis[i.first]) dfs(i.first, x);
    }
  }
  s.erase(nod);
  ans.push_back(nod);
}
bool isOk(int x) {
  memset(vis, 0, sizeof(vis));
  s.clear();
  ans.clear();
  flg = 1;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i, x);
  }
  return flg;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> w;
    vec[u].push_back({v, w});
    ed[i + 1] = {{u, v}, w};
  }
  long long st = 0;
  long long en = 1000000007ll;
  long long res = 0;
  while (st <= en) {
    int mid = (st + en) / 2;
    if (isOk(mid)) {
      en = mid - 1;
      res = mid;
    } else {
      st = mid + 1;
    }
  }
  isOk(res);
  for (int i = 0; i < ans.size(); i++) {
    pos[ans[i]] = i;
  }
  vector<int> ret;
  for (int i = 1; i <= m; i++) {
    u = ed[i].first.first;
    v = ed[i].first.second;
    if (pos[u] < pos[v]) {
      ret.push_back(i);
    }
  }
  cout << res << " " << ret.size() << endl;
  for (auto i : ret) cout << i << " ";
  cout << endl;
  return 0;
}
