#include "bits/stdc++.h"
using namespace std;

#define REP(i, s, n) for(int i = (s); i < int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(co) co.begin(), co.end()

int dp[201][201];

int main()
{
	int d, n; cin >> d >> n;
	vector<int> ts(d), as(n), bs(n), cs(n);
	rep(i, d) cin >> ts[i];
	rep(i, n) cin >> as[i] >> bs[i] >> cs[i];

	rep(i, n) if (ts[0] < as[i] || bs[i] < ts[0]) dp[0][i] = -(1 << 29);
	REP(i, 1, d) rep(j, n)
	{
		int t = ts[i], a = as[j], b = bs[j], c = cs[j];
		if (a <= t && t <= b) rep(k, n)
		{
			dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(cs[k] - c));
		}
	}

	cout << *max_element(dp[d - 1], dp[d - 1] + n) << endl;

	return 0;
}