#include <bits/stdc++.h>
using namespace std;
int n, m, poz[1000000 + 100];
bool obidjen[1000000 + 100];
struct node {
  int l, r, d;
};
node a[1000000 + 100];
bool cmp(node a, node b) { return min(a.r, a.l) < min(b.r, b.l); }
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &a[i].l, &a[i].r, &a[i].d);
  }
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    int idx = a[i].l;
    int idx2 = a[i].r;
    int smer = 1;
    if (a[i].r < a[i].l) idx = a[i].r, idx2 = a[i].l, smer = -1;
    if (!obidjen[idx]) obidjen[idx] = 1, poz[idx] = 0;
    if (obidjen[idx2] && poz[idx2] != a[i].d * smer + poz[idx]) {
      cout << "NO" << endl;
      return 0;
    }
    if (!obidjen[idx2]) obidjen[idx2] = 1, poz[idx2] = a[i].d * smer + poz[idx];
  }
  cout << "YES" << endl;
  return 0;
}
