#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1 * 1000 * 1000 * 1000 + 200;
const int MAXN = 100 * 1000 + 10;
const int MLOG = 30;
const int NMAX = 20;
int n, mark[MAXN];
vector<pair<int, int>> adj[MAXN];
void dfs(int a) {
  for (auto pr : adj[a]) {
    if (!mark[pr.first]) {
      mark[pr.first] = mark[a] + pr.second;
      dfs(pr.first);
    }
  }
}
bool check() {
  for (int i = 0; i < n; i++) {
    for (auto pr : adj[i]) {
      if (mark[i] == mark[pr.first] - pr.second)
        continue;
      else
        return false;
    }
  }
  return true;
}
signed main() {
  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    adj[l].push_back({r, d});
    adj[r].push_back({l, -d});
  }
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      mark[i] = INF;
      dfs(i);
    }
  }
  if (check())
    cout << "YES";
  else
    cout << "NO";
}
