#include <cstdio>
#include <cstdlib>
#include <algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	int d,n; scanf("%d%d",&d,&n);
	int t[200],a[200],b[200],c[200];
	rep(i,d) scanf("%d",t+i);
	rep(i,n) scanf("%d%d%d",a+i,b+i,c+i);

	int dp[201][101];
	rep(i,d) rep(j,101) dp[i][j]=-INF;
	rep(k,n) if(a[k]<=t[0] && t[0]<=b[k]) dp[0][c[k]]=0;
	rep(i,d-1) rep(j,101) {
		rep(k,n) if(a[k]<=t[i+1] && t[i+1]<=b[k]) dp[i+1][c[k]]=max(dp[i+1][c[k]],dp[i][j]+abs(c[k]-j));
	}
	printf("%d\n",*max_element(dp[d-1],dp[d-1]+101));

	return 0;
}