#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long n, m, top, vis[N], dis[N], head[N];
struct node {
  long long too, Next, zh;
} edge[N];
void add(long long a, long long b, long long c) {
  edge[++top].too = b;
  edge[top].zh = c;
  edge[top].Next = head[a];
  head[a] = top;
}
inline long long read() {
  long long ret = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    ret = ret * 10 + c - 48;
    c = getchar();
  }
  if (f) return -ret;
  return ret;
}
void dfs(long long u, long long dep) {
  if (vis[u]) {
    if (dis[u] != dep) {
      puts("NO");
      exit(0);
    }
    return;
  }
  vis[u] = 1;
  dis[u] = dep;
  for (long long i = head[u]; i; i = edge[i].Next) {
    long long v = edge[i].too, w = edge[i].zh;
    dfs(v, dep + w);
  }
}
signed main() {
  n = read(), m = read();
  for (long long i = 1; i <= m; i++) {
    long long x = read(), y = read(), z = read();
    add(x, y, z);
    add(y, x, -z);
  }
  for (long long i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  puts("YES");
}
