#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#define int long long
#define mod 1000000007
using namespace std;
int d, n, t[250], a[250], b[250], c[250], dp[250][250], ans;
signed main() {
	cin >> d >> n;
	for (int i = 1; i <= d; i++) cin >> t[i];
	for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
	for (int i = 1; i <= n; i++)if (t[1] < a[i] || b[i] < t[1])dp[1][i] = -100000000;
	for (int i = 2; i <= d; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = -100000000;
			if (a[j] <= t[i] && t[i] <= b[j])
				for (int k = 1; k <= n; k++) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(c[k] - c[j]));
				}
			if (i == d)ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
}
