#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  vector<int> child[100010];
  int dist[100010];
  int top[100010];
  bool can = true;
  cin >> N >> M;
  for (int i = ((int)(0)); i <= ((int)(N)); i++) {
    dist[i] = 0;
    top[i] = i;
  }
  for (int i = 0; i < ((int)(M)); i++) {
    int l, r, d;
    scanf("%d%d%d", &l, &r, &d);
    if (top[l] == top[r]) {
      if (dist[l] != dist[r] + d) {
        can = false;
        break;
      }
    } else {
      int greatest, dif;
      dif = abs(dist[l] - (dist[r] + d));
      if (dist[l] > dist[r] + d) {
        for (int i = 0; i < ((int)(child[top[r]].size())); i++) {
          int a = child[top[r]][i];
          top[a] = top[l];
          dist[a] += dif;
          child[top[l]].push_back(a);
        }
        child[top[l]].push_back(top[r]);
        dist[top[r]] += dif;
        top[r] = top[l];
      } else {
        for (int i = 0; i < ((int)(child[top[l]].size())); i++) {
          int a = child[top[l]][i];
          top[a] = top[r];
          dist[a] += dif;
          child[top[r]].push_back(a);
        }
        child[top[r]].push_back(top[l]);
        dist[top[l]] += dif;
        top[l] = top[r];
      }
    }
  }
  if (can) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
