#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int power(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int maxn = 1e5 + 3;
int n, m;
vector<pair<int, pair<int, int> > > g[maxn];
vector<int> tg[maxn];
vector<int> sequence;
int toposortSize() {
  vector<int> indegree(n + 1, 0);
  sequence.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < tg[i].size(); j++) {
      int v = tg[i][j];
      indegree[v]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (indegree[i] == 0) {
      sequence.push_back(i);
    }
  }
  int idx = 0;
  while (idx < sequence.size()) {
    int cur = sequence[idx];
    idx++;
    for (int i = 0; i < tg[cur].size(); i++) {
      int v = tg[cur][i];
      indegree[v]--;
      if (indegree[v] == 0) {
        sequence.push_back(v);
      }
    }
  }
  return sequence.size();
}
void make_graph(int maxW) {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      int v = g[i][j].first;
      int wt = g[i][j].second.first;
      if (wt > maxW) {
        tg[i].push_back(v);
      }
    }
  }
}
bool good(int maxW) {
  make_graph(maxW);
  return toposortSize() == n;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int maxW = 0;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back(make_pair(v, make_pair(w, i)));
    maxW = max(maxW, w);
  }
  int lo = 0;
  int hi = maxW;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    for (int i = 1; i <= n; i++) {
      tg[i].clear();
    }
    if (good(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo << " ";
  for (int i = 1; i <= n; i++) {
    tg[i].clear();
  }
  make_graph(lo);
  toposortSize();
  vector<int> pos(n + 1);
  for (int i = 0; i < sequence.size(); i++) {
    pos[sequence[i]] = i;
  }
  vector<int> edges;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      int from = i;
      int to = g[i][j].first;
      int idx = g[i][j].second.second;
      if (pos[from] > pos[to]) {
        edges.push_back(idx);
      }
    }
  }
  cout << edges.size() << endl;
  sort(edges.begin(), edges.end());
  for (int i = 0; i < edges.size(); i++) {
    cout << edges[i] << " ";
  }
  cout << endl;
  return 0;
}
