#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

const int INF = -100000000;

int main(){
  int d,n,a[200],b[200],c[200],t[200];
  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);
  int dp[200][200];
  fill(dp[0],dp[0]+200,INF);
  for(int i=0;i<d;i++){
    for(int j=0;j<n;j++){
      if(i==0){
        if(a[j]<=t[i]&&t[i]<=b[j]){
          dp[i][j] = 0;
        }
        continue;
      }
      dp[i][j] = 0;
      for(int k=0;k<n;k++){
        if(a[j]<=t[i]&&t[i]<=b[j]){
          dp[i][j] = max(dp[i][j],dp[i-1][k]+max(c[j],c[k])-min(c[j],c[k]));
        }
      }
    }
  }
  int ans = 0;
  for(int i=0;i<n;i++) ans = max(ans,dp[d-1][i]);
  printf("%d\n",ans);
  return 0;
}