#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

int D, N;
int T[256], A[256], B[256], C[256];
int dp[256][256];

int rec(int day, int prev)
{
	if(day == D) return 0;

	
}

int main()
{
	memset(dp, 0, sizeof dp);
	
	cin >> D >> N;

	for(int i = 0; i < D; i++) {
		cin >> T[i];
	}

	for(int i = 0; i < N; i++) {
		cin >> A[i] >> B[i] >> C[i];
	}

	for(int day = 0; day < D-1; day++) {
		for(int now = 0; now < N; now++) {
			for(int next = 0; next < N; next++) {
				if(A[now] <= T[day] && T[day] <= B[now] && A[next] <= T[day+1] && T[day+1] <= B[next]) {
					dp[day+1][next] = max(int(dp[day+1][next]), int(dp[day][now] + abs(C[now] - C[next])));
				}
			}
		}
	}

	int ans = 0;
	for(int i = 0; i < N; i++) {
		ans = max(ans, dp[D-1][i]);
	}

	cout << ans << endl;
}