#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

struct Clothes {
	int a, b, c;
};

int main() {
	int dp[201][200] = {};
	int d, n, mt[200];
	Clothes clothes[200];

	cin >> d >> n;
	REP(i, d) scanf("%d", &mt[i]);
	REP(i, n) scanf("%d %d %d", &clothes[i].a, &clothes[i].b, &clothes[i].c);
	
	REP(i, d - 1) {
		REP(j, n) {
			if (clothes[j].a > mt[i] || clothes[j].b < mt[i]) continue;
			REP(k, n) {
				if (clothes[k].a > mt[i+1] || clothes[k].b < mt[i+1]) continue;
				dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abs(clothes[k].c - clothes[j].c));
			}
		}
	}

	int ans = 0;
	REP(i, n) ans = max(ans, dp[d - 1][i]);
	cout << ans << endl;

	return 0;
}