#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
const int M = 1e9 + 7;
const double eps = 1e-6;
const double PI(acos(-1.0));
using namespace std;
int p[N], w[N], n, m;
int find(int x) {
  if (x == p[x]) return x;
  int t = find(p[x]);
  w[x] += w[p[x]];
  return p[x] = t;
}
int main() {
  cin >> n >> m;
  for (int i = (1); i <= (n); i++) p[i] = i;
  for (int i = 0; i < (m); i++) {
    int l, r, d;
    cin >> l >> r >> d;
    int x = find(l), y = find(r);
    if (x == y && w[l] + d != w[r]) {
      puts("NO");
      return 0;
    } else {
      p[y] = x;
      w[y] = w[l] + d - w[r];
    }
  }
  puts("YES");
}
