3 5
2 1 608591421 720962564
3 2 608591421 641991574
3 2 718110706 353409763
2 3 482786015 858341723
3 2 825397574 357507279
 2 1
2 1 317425595 636156322
 50000 1
20845 28516 904146168 997637433

Yes
641991574 1
2 
 Yes
0 0

 Yes
0 0


#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5;
const int MAXN = 5e4 + 20;
int n, m, ec, cl;
int comp[2 * MAX];
vector<int> adj[MAXN];
vector<int> ss[2 * MAX], rev_ss[2 * MAX];
bool mark[2 * MAX], seen[2 * MAX];
map<int, int> cnt, first;
int col[2 * MAX], tm[2 * MAX];
int id[2 * MAX];
vector<int> st, sst;
bool ans[2 * MAX];
bool check() {
  for (int i = 0; i < n; i++) {
    int cc = 0;
    for (int e : adj[i]) {
      cnt[col[e]]++;
      if (cnt[col[e]] == 3) return true;
      if (cnt[col[e]] == 2) {
        int f = first[col[e]];
        ss[e + MAX].push_back(f);
        ss[f + MAX].push_back(e);
        cc++;
      }
      if (cc > 1) return true;
      if (cnt[col[e]] == 1) first[col[e]] = e;
    }
    first.clear();
    cnt.clear();
  }
  return false;
}
void build(int v, int b, int e, int p) {
  if (e - b == 1) {
    id[v] = adj[p][b];
    return;
  }
  int mid = (b + e) / 2;
  build(v << 1, b, mid, p);
  build(v << 1 ^ 1, mid, e, p);
  id[v] = ec++;
  ss[id[v << 1]].push_back(id[v]);
  ss[id[v << 1 ^ 1]].push_back(id[v]);
  ss[id[v] + MAX].push_back(id[v << 1] + MAX);
  ss[id[v] + MAX].push_back(id[v << 1 ^ 1] + MAX);
  for (; b < e; b++) {
    ss[id[v] + MAX].push_back(adj[p][b] + MAX);
    ss[adj[p][b]].push_back(id[v]);
  }
}
void dfs(int v) {
  seen[v] = 1;
  for (int u : ss[v])
    if (!seen[u]) dfs(u);
  st.push_back(v);
}
void kosaraju(int v) {
  comp[v] = cl;
  seen[v] = 1;
  for (int u : rev_ss[v])
    if (!seen[u]) kosaraju(u);
  sst.push_back(v);
}
bool ok() {
  memset(seen, 0, sizeof(seen));
  st.clear();
  sst.clear();
  for (int i = 0; i < n; i++)
    if (!seen[i]) dfs(i);
  for (int i = MAX; i < MAX + ec; i++)
    if (!seen[i]) dfs(i);
  {
    for (int i = 0; i < ec; i++) rev_ss[i].clear();
    for (int i = MAX; i < MAX + ec; i++) rev_ss[i].clear();
    for (int i = 0; i < ec; i++)
      for (int u : ss[i]) rev_ss[u].push_back(i);
    for (int i = MAX; i < MAX + ec; i++)
      for (int u : ss[i]) rev_ss[u].push_back(i);
  }
  reverse(st.begin(), st.end());
  memset(seen, 0, sizeof(seen));
  cl = 1;
  for (int u : st)
    if (!seen[u]) kosaraju(u), cl++;
  for (int i = 0; i < ec; i++)
    if (comp[i] == comp[i + MAX]) return false;
  return true;
}
void add(int v, int b, int e, int num, int ind) {
  if (e - b == 1) {
    if (b == ind) return;
    ss[num].push_back(id[v] + MAX);
    return;
  }
  if (ind < b || e <= ind) {
    ss[num].push_back(id[v] + MAX);
    return;
  }
  int mid = (b + e) / 2;
  add(v << 1, b, mid, num, ind);
  add(v << 1 ^ 1, mid, e, num, ind);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b >> col[ec] >> tm[ec];
    a--, b--;
    adj[a].push_back(ec);
    adj[b].push_back(ec);
    ec++;
  }
  if (check())
    cout << "No\n";
  else {
    for (int i = 0; i < n; i++) {
      int t = adj[i].size();
      build(1, 0, t, i);
      for (int j = 0; j < t; j++) add(1, 0, t, adj[i][j], j);
    }
    memset(mark, 0, sizeof(mark));
    int b = 0, e = 1e9, mid, ret = -1;
    while (b <= e) {
      mid = (b + e) / 2;
      for (int i = 0; i < m; i++) {
        if (mark[i]) ss[i].pop_back();
        mark[i] = 0;
        if (tm[i] > mid) {
          mark[i] = 1;
          ss[i].push_back(i + MAX);
        }
      }
      if (ok()) {
        ret = mid;
        e = mid - 1;
      } else
        b = mid + 1;
    }
    if (ret == -1)
      cout << "NO\n";
    else {
      cout << "Yes\n";
      cout << ret << " ";
      for (int i = 0; i < m; i++) {
        if (mark[i]) ss[i].pop_back();
        mark[i] = 0;
        if (tm[i] > ret) {
          mark[i] = 1;
          ss[i].push_back(i + MAX);
        }
      }
      ok();
      reverse(sst.begin(), sst.end());
      memset(seen, 0, sizeof(seen));
      for (int u : sst) {
        if (seen[comp[u]]) continue;
        int z = u;
        if (u >= MAX)
          z -= MAX;
        else
          z += MAX;
        if (seen[comp[z]]) {
          seen[comp[u]] = 1;
          ans[comp[u]] = !ans[comp[z]];
          continue;
        }
        seen[comp[u]] = 1;
        ans[comp[u]] = 1;
      }
      int cans = 0;
      for (int i = 0; i < m; i++)
        if (ans[comp[i]]) cans++;
      cout << cans << endl;
      for (int i = 0; i < m; i++)
        if (ans[comp[i]]) cout << i + 1 << " ";
      cout << endl;
    }
  }
  return 0;
}
