#include <bits/stdc++.h>
using namespace std;
using tpl = tuple<int, int, int>;
void fastStream() {
  cin.tie(0);
  std::ios_base::sync_with_stdio(0);
}
int N, M;
int L[200100];
int R[200100];
int D[200100];
int points[200100];
vector<tpl> G[200100];
const int INF = (1 << 30);
bool rec(int pos) {
  for (tpl p : G[pos]) {
    int to = get<0>(p);
    int dist = get<1>(p);
    int ang = get<2>(p);
    int next = points[pos] + dist * ang;
    if (points[to] != -INF) {
      if (next != points[to]) {
        return false;
      }
    } else {
      points[to] = next;
      if (!rec(to)) return false;
    }
  }
  return true;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i] >> D[i];
    L[i]--;
    R[i]--;
    G[L[i]].push_back(tpl(R[i], D[i], +1));
    G[R[i]].push_back(tpl(L[i], D[i], -1));
  }
  for (int i = 0; i < N; i++) points[i] = -INF;
  for (int i = 0; i < N; i++) {
    if (points[i] == -INF) {
      points[i] = 0;
      if (!rec(i)) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
