#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <climits>
#include <sstream>
#include <functional>
#include <complex>

using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define Rep(i, e) for(int i = 0;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define Rrep(i, e) for(int i = e;0 <= i;i--)
#define mrep(i, e, t1, t2) for(map<t1, t2>::iterator i = e.begin(); i != e.end(); i++)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define fmax(a, b) (a < b? b : a)
#define fmin(a, b) (a > b? b : a)
#define fabs(a) (a < 0? -a : a)
#define pb push_back
#define rg(e, s, t) s <= e && e < t
#define PQDecl(name, tp) priority_queue< tp, vector<tp>, greater<tp> > name;
//#define X real()
//#define Y imag()
//typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef complex<double> p;
const int INF = (int)2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
//const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const ll weight[] = {1e0,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13};
#define MAX_N 1000

typedef struct _Node {
  _Node(int arg1 = 0, int arg2 = 0 , int arg3 = 0) {
	i = arg1;
	j = arg2;
	k = arg3;
  }
  int i,j,k;
  bool operator <(const struct _Node &e) const{
    return i == e.i? (j == e.j? k < e.k : j < e.j) : i < e.i;
  }
  bool operator >(const struct _Node &e) const{
    return i == e.i? (j == e.j? k > e.k : j > e.j) : i > e.i;
  }
}node;

void doIt(){
  int l, n;
  node magic[MAX_N];
  cin >> l >> n;
  Rep(i, n){
    cin >> magic[i].i >> magic[i].j >> magic[i].k;
  }
  sort(magic, magic + n);
  map<ll, ll> mmap[2];
  int prev = 1, now = 0;
  mmap[prev][0] = 0;
  Rep(i, n){
    mmap[now].clear();
    mrep(it, mmap[prev], ll, ll){
      ll e = (*it).first, time = (*it).second;
      // printf("i = %d, e = %lld, time = %lld\n", i, e, time);
      //先にいたら
      if(magic[i].i < e){
        if(mmap[now].count(e)){
          mmap[now][e] = fmin(mmap[now][e], time);
        }
        else{
          mmap[now][e] = time;
        }
      }
      else{
        ll dist = magic[i].i + magic[i].j;
        //warp
        if(mmap[now].count(dist)){
          mmap[now][dist] = fmin(mmap[now][dist], time + magic[i].i - e + magic[i].k);
        }
        else{
          mmap[now][dist] = time + magic[i].i - e + magic[i].k;
        }
        //not warp
        if(mmap[now].count(magic[i].i)){
          mmap[now][magic[i].i] = fmin(mmap[now][magic[i].i], time + magic[i].i - e);
        }
        else{
          mmap[now][magic[i].i] = time + magic[i].i - e;
        }
      }
    }
    prev = 1 - prev;
    now = 1 - now;
  }
  ll ans = l;
  mrep(it, mmap[prev], ll, ll){
    ans = fmin(ans, (*it).second + l - (*it).first);
  }
  cout << ans << endl;
}

int main() {
  doIt();
  return 0;
}


Measured memory_bytes: 1248