#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
int t[200],a[200],b[200],c[200],dp[201][201],D,N;
int solve(int today,int yd){ //今日の日付, 昨日の服の番号
  if(today == D) return 0;
  if(dp[today][yd]) return dp[today][yd];
  int res = 0;
  for(int i = 0 ; i < N ; i++ ){
    if( t[today] >= a[i] && t[today] <= b[i] ){
      res = max(res,solve(today+1,i) + (today?abs(c[i]-c[yd]):0));
    }
  }
  return dp[today][yd] = res;
}
int main(){
  cin >> D >> N;
  rep(i,D) cin >> t[i];
  rep(i,N) cin >> a[i] >> b[i] >> c[i];
  cout << solve(0,0) << endl;
}