#include <bits/stdc++.h>
const int MAXN = 1e5;
using namespace std;
inline int read() {
  int x = 0, w = 1;
  char c = ' ';
  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * w;
}
int n = read(), m = read();
class Ufs {
 public:
  Ufs() {
    for (int i = 1; i <= n; ++i) fa[i] = i, rk[i] = 1;
  }
  int find(int x);
  bool UnionSet(int x, int y, int w);

 private:
  int fa[MAXN + 5], rk[MAXN + 5], v[MAXN + 5];
} S;
int Ufs::find(int x) {
  if (x == fa[x]) return fa[x];
  int t = find(fa[x]);
  v[x] += v[fa[x]];
  fa[x] = t;
  return fa[x];
}
bool Ufs::UnionSet(int x, int y, int w) {
  int p = find(x), q = find(y);
  if (p != q) {
    if (rk[p] < rk[q]) {
      fa[p] = fa[q], v[p] = v[y] - v[x] - w;
    } else {
      if (rk[p] == rk[q]) ++rk[q];
      fa[q] = fa[p], v[q] = v[x] + w - v[y];
    }
  } else if (v[y] - v[x] != w)
    return false;
  return true;
}
int l[MAXN + 5], r[MAXN + 5], d[MAXN + 5];
int main() {
  ;
  for (int i = 1; i <= m; ++i) {
    int L = read(), R = read(), D = read();
    if (!S.UnionSet(L, R, D)) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
