using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        bool result = true;
        int count = int.Parse(Console.ReadLine().Split()[1]);
        var _list = new HashSet<Dictionary<int, int>>();
        const int MAX = 1000000000;
        for (int i = 0; i < count; ++i)
        {
            var sp = Console.ReadLine().Split();
            if (!result) continue;
            int left = int.Parse(sp[0]);
            int right = int.Parse(sp[1]);
            int diff = int.Parse(sp[2]);
            var dicL = _list.FirstOrDefault(d => d.ContainsKey(left));
            var dicR = _list.FirstOrDefault(d => d.ContainsKey(right));
            if (dicL == null)
            {
                if (dicR == null)
                {
                    _list.Add(new Dictionary<int, int>() { { left, 0 }, { right, diff } });
                }
                else
                {
                    dicR[left] = dicR[right] - diff;
                }
            }
            else
            {
                if (dicR == null)
                {
                    int tmp = dicL[left] + diff;
                    if (MAX < tmp) result = false;
                    dicL[right] = tmp;
                }
                else if (dicL == dicR)
                {
                    result &= (dicL[left] + diff == dicL[right]);
                }
                else
                {
                    int move = dicL[left] + diff - dicR[right];
                    foreach (var pair in dicR)
                    {
                        if (dicL.ContainsKey(pair.Key))
                        {
                            if (dicL[pair.Key] != pair.Value + move)
                            {
                                result = false;
                                break;
                            }
                        }
                        else
                        {
                            int tmp = pair.Value + move;
                            if (MAX < tmp) result = false;
                            dicL[pair.Key] = tmp;
                        }
                    }
                    _list.Remove(dicR);
                }
            }
        }
        if (result)
        {
            foreach(var dic in _list)
            {
                int min = int.MaxValue, max = 0;
                foreach(var val in dic.Values)
                {
                    min = Math.Min(min, val);
                    max = Math.Max(max, val);
                }
                if (max - min > 1000000000)
                {
                    result = false;
                    break;
                }
            }
        }
        Console.WriteLine(result ? "YES" : "NO");
    }
}
