#include <bits/stdc++.h>
using namespace std;
#define MAX_D (200)
#define MAX_N (200)

int d, n;
int t[MAX_D];
int a[MAX_N], b[MAX_N], c[MAX_N];

int dp[MAX_D + 1][MAX_N];
// dp[ ?????\????????§??????????????? ][ ?????????????????? ] = ?´??????????????¨?

int search(int i, int last)
{
	int &res = dp[i][last];
	
	if (res != -1) return (res);
	
	if (i == d) return (res = 0);
	
	for (int j = 0; j < n; j++){
		if (t[i] < a[j] || b[j] < t[i]) continue;
		int sub = abs(c[last] - c[j]);
		res = max(res, sub + search(i + 1, j));
	}
	
	return (res);
}

int main()
{
	scanf("%d %d", &d, &n);
	for (int i = 0; i < d; i++){
		scanf("%d", &t[i]);
	}
	for (int i = 0; i < n; i++){
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
	}
	
	memset(dp, -1, sizeof(dp));
	
	int ans = 0;
	for (int i = 0; i < n; i++){
		if (t[0] < a[i] || b[i] < t[0]) continue;
		ans = max(ans, search(1, i));
	}
	
	printf("%d\n", ans);
	
	return 0;
}