#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;
using ld = long double;
using ll = long long;
const int inf = 2e9, mod = 1e9 + 7;
const ll INF = 9e18;
const ld EPS = 1e-9, PI = acosl(-1.0);
const int N = 1e5 + 5;
int n, m, l, r, d;
vector<vector<pair<int, int>>> g(N);
bitset<N> vis;
int ans[N];
set<int> st;
int poss = 1;
void dfs(int u) {
  vis[u] = 1;
  st.insert(ans[u]);
  for (auto nxt : g[u]) {
    int nd = nxt.second + ans[u];
    if (vis[nxt.first])
      poss &= nd == ans[nxt.first];
    else {
      ans[nxt.first] = nd;
      dfs(nxt.first);
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0, _i = (m); i < _i; ++i) {
    cin >> l >> r >> d;
    g[l].push_back(make_pair(r, d));
    g[r].push_back(make_pair(l, -d));
  }
  const int MX = 1e9;
  for (int i = (1), _i = (n + 1); i < _i; ++i) {
    if (!vis[i]) {
      st.clear();
      ans[i] = 0;
      dfs(i);
      if (!st.empty() && (*(st.rbegin()) - *(st.begin())) > MX) poss = 0;
    }
  }
  cout << (poss ? "YES" : "NO");
}
