#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

#define M 210

#define pb push_back
#define mp make_pair

using namespace std;

int main(void)
{
	int d,n;
	int a,b,c;
	int i1,i2,i3;
	int maxx;

	cin>>d>>n;

	vector<int> t(d);
	vector<pair<int,int> > cl[M]; 

	for(i1=0;i1<d;i1++){
		cin>>t[i1];
	}
	for(i1=0;i1<n;i1++){
		cin>>a>>b>>c;
		
		for(i2=0;i2<d;i2++){
			if(a<=t[i2] && t[i2]<=b) cl[i2].pb(mp(c,0));
		}
	}

	maxx=0;
	for(i1=1;i1<d;i1++){

		for(i2=0;i2<cl[i1].size();i2++){
			for(i3=0;i3<cl[i1-1].size();i3++){
				cl[i1][i2].second=max(cl[i1][i2].second,abs(cl[i1][i2].first-cl[i1-1][i3].first)+cl[i1-1][i3].second);
				//cout<<cl[i1][i3].first<<" "<<" "<<cl[i1][i2].first<<" "<<cl[i1][i2].second<<endl;
			}
			maxx=max(maxx,cl[i1][i2].second);
		}
		//cout<<endl;
	}

	cout<<maxx<<endl;

	return 0;
}