#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 200010;
struct edge {
  int to, next, val;
} e[M];
int head[N], tot = 0;
void add_edge(int u, int v, int val) {
  e[tot].to = v;
  e[tot].val = val;
  e[tot].next = head[u];
  head[u] = tot++;
}
int in[N], dis[N];
int n, m, l, r, d;
int main() {
  scanf("%d%d", &n, &m);
  memset(head, -1, sizeof(head));
  memset(dis, 0x3f3f3f3f, sizeof(dis));
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &l, &r, &d);
    add_edge(l, r, d);
    in[r]++;
  }
  queue<pair<int, int> > q;
  for (int i = 1; i <= n; i++) {
    if (!in[i]) q.push(make_pair(i, 0));
  }
  if (m > 0 && q.empty()) {
    printf("NO\n");
    return 0;
  }
  int cnt = 0;
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    if (dis[cur.first] == 0x3f3f3f3f) {
      cnt++;
      dis[cur.first] = cur.second;
      for (int i = head[cur.first]; i != -1; i = e[i].next) {
        int to = e[i].to;
        q.push({to, cur.second + e[i].val});
      }
    } else {
      if (dis[cur.first] != cur.second) {
        printf("NO\n");
        return 0;
      }
    }
  }
  if (cnt == n)
    printf("YES\n");
  else
    printf("NO\n");
}
