#include <bits/stdc++.h>
using namespace std;
long long dis[100005];
int group[100005];
int siz[100005];
vector<int> member[100005];
int find_set(int v) {
  return v == group[v] ? v : group[v] = find_set(group[v]);
}
int Union(int v1, int v2, int d) {
  int l1 = find_set(v1);
  int l2 = find_set(v2);
  if (l1 == l2) {
    if (dis[v2] == dis[v1] + d)
      return 1;
    else
      return 0;
  }
  int t = 0;
  if (member[l1].size() > member[l2].size()) {
    swap(l1, l2);
    t = 1;
  }
  int v = dis[v2] - d - dis[v1];
  if (t) v = -v;
  for (int i = 0; i < (member[l1].size()); ++i) {
    dis[member[l1][i]] += v;
    member[l2].push_back(member[l1][i]);
  }
  group[l1] = l2;
  return 1;
}
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = (1); i < (n + 1); ++i) {
    dis[i] = 0;
    group[i] = i;
    member[i].push_back(i);
  }
  bool flag = 0;
  for (int i = 0; i < (m); ++i) {
    int v1, v2, d;
    scanf("%d %d %d", &v1, &v2, &d);
    if (flag) continue;
    int r = Union(v1, v2, d);
    if (!r) flag = 1;
  }
  if (flag)
    puts("NO");
  else
    puts("YES");
  return 0;
}
