#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, inf = 1e9 + 7;
long long n, k, i, j;
long long A[N], seg[N], vis[N], seq[N], cnt;
std::vector<pair<long long, long long> > adj[N], ed;
vector<long long> rev;
bool dfs(long long cur, long long mn) {
  if (vis[cur] == 2) return 1;
  if (vis[cur]) return 0;
  vis[cur] = 2;
  for (auto i : adj[cur])
    if (i.second > mn && dfs(i.first, mn)) return 1;
  seq[cur] = ++cnt;
  vis[cur] = 1;
  return 0;
}
bool check(long long cur) {
  cnt = 0;
  memset(vis, 0, sizeof vis);
  for (i = 1; i < n + 1; i++)
    if (!vis[i])
      if (dfs(i, cur)) return 0;
  return 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, a, b, ans = 0, c;
  cin >> n >> k;
  for (i = 0; i < k; i++) {
    cin >> a >> b >> c;
    ed.emplace_back(pair<long long, long long>(a, b));
    adj[a].emplace_back(pair<long long, long long>(b, c));
  }
  long long low = 0, high = inf - 1, mid;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check(mid)) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  check(ans);
  for (i = 0; i < k; i++)
    if (seq[ed[i].first] < seq[ed[i].second]) rev.emplace_back(i + 1);
  cout << ans << " " << (long long)rev.size() << "\n";
  for (auto i : rev) cout << i << " ";
}
