#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long> > > graph;
const long long N = 100005;
long long head[N], ans[N];
vector<long long> check;
bool flag = 1;
void Init(long long n) { iota(head, head + n, 0); }
long long Find(long long x) { return (x == head[x]) ? x : x = Find(head[x]); }
void Union(long long x, long long y) {
  if (Find(x) == Find(y)) return;
  head[Find(x)] = Find(y);
}
void dfs(long long u) {
  if (check[u] == -1) check[u] = 1;
  for (__typeof((long long)graph[u].size()) i = 0;
       i < (long long)graph[u].size(); i++) {
    pair<long long, long long> t = graph[u][i];
    if (check[t.first] == -1) {
      ans[t.first] = ans[u] - t.second;
      dfs(t.first);
    } else {
      if (ans[u] - t.second != ans[t.first]) flag = 0;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  graph.assign(n, vector<pair<long long, long long> >());
  check.assign(n, -1);
  Init(n);
  long long l, r, d;
  for (__typeof(n) i = 0; i < n; i++) ans[i] = -1;
  for (__typeof(m) i = 0; i < m; i++) {
    cin >> l >> r >> d;
    l--;
    r--;
    Union(l, r);
    graph[r].emplace_back(make_pair(l, d));
  }
  for (__typeof(n) i = 0; i < n; i++) {
    if (check[i] == -1) {
      ans[Find(i)] = 1000000000;
      dfs(Find(i));
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
