#include <bits/stdc++.h>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 19260817;
pair<pair<int, int>, int> p[200001];
vector<pair<int, int> > vt[100001];
long long a[100001];
long long f[100001];
bool u[100001];
int ypa(int k) {
  u[k] = 1;
  for (int i = 0; i < vt[k].size(); i++) {
    if (u[vt[k][i].first]) {
      if (a[vt[k][i].first] != a[k] - vt[k][i].second) {
        puts("NO");
        exit(0);
      }
    } else {
      a[vt[k][i].first] = a[k] - vt[k][i].second;
      ypa(vt[k][i].first);
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (m == 0) {
    puts("YES");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &p[i].first.first, &p[i].first.second, &p[i].second);
    vt[p[i].first.first].push_back(make_pair(p[i].first.second, p[i].second));
  }
  ypa(p[1].first.first);
  puts("YES");
  return 0;
}
