#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define mmt(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define inf 1e9
#define M 1000100
#define N 1010
#define MaxL 1001000
using namespace std;
typedef long long LL;
typedef long double LD;
int len=1,maxflow=0,n,m,i,w[M];
int pre[M],last[M],e[M],ca[M],co[M],q[MaxL+1000],dis[N],vis[N],path[M],source,target;
void add(int x,int y,int z,int w)
{
  pre[++len]=last[x],last[x]=len,e[len]=y,ca[len]=z,co[len]=w;
  pre[++len]=last[y],last[y]=len,e[len]=x,ca[len]=0,co[len]=-w;
}
int Nxt(int x){if (x==MaxL-1) return 1;return x+1;}
int MCMF()
{
  int __ans=0;
  while(1)
  {
    memset(dis,0x7e,sizeof(dis));
    memset(vis,0,sizeof(vis));
    int h=0,t=1;
    q[1]=source,vis[source]=0,dis[source]=0;
    while(h<t)
    {
      h=Nxt(h);int u=q[h];
      for(int p=last[u];p;p=pre[p])
      {
        int v=e[p],rm=ca[p],Cost=co[p];
        if(rm&&dis[u]+Cost<dis[v])
        {
          dis[v]=dis[u]+Cost,path[v]=p;
          if(!vis[v])
          {
            t=Nxt(t);
            q[t]=v;
            vis[v]=1;
          }
        }
      }
      vis[u]=0;
    }
    if(dis[target]==0x7e7e7e7e)break;
    int tf=inf;
    for(int u=target;u!=source;u=e[path[u]^1])tf=min(tf,ca[path[u]]);
    maxflow+=tf,__ans+=tf*dis[target];
    for(int u=target;u!=source;u=e[path[u]^1]) ca[path[u]]-=tf,ca[path[u]^1]+=tf;
  }
  return __ans;
}
int main()
{
  ios::sync_with_stdio(false);
  scanf("%d%d",&n,&m);int x,y,z,i;
  FOR(i,1,n) scanf("%d",&w[i]);w[0]=w[n+1]=0;
  FOR(i,1,m)
  {
    scanf("%d%d%d",&x,&y,&z);
    add(x,y+1,inf,z);
  }
  source=n+2;target=n+3;
  ROF(i,n+1,1)
  {
    int t=w[i]-w[i-1];
    if (i>1) add(i,i-1,inf,0);
    if (t>=0) add(source,i,t,0);else add(i,target,-t,0);
  }
  printf("%d\n",MCMF());
  return 0;
}