import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner (System.in);
		int d = sc.nextInt(); // d??\?????????????????????
		int n = sc.nextInt(); // n?¨???????????????????
		int niti[] = new int [d]; //??\?????¨??????????°??????\??????
		int low[] = new int [n];  //???????????£???????°????
		int high [] = new int[n];  //???????????£???????°????
		int point [] = new int [n];//?´???????????????????
		int select[][] ;//??????????????£?????????????????\??????????´?????????????????????\?????????
		select = new int [d][n];
		int count = 0;//select??§????????????1??\????????????????????????
		int huku[] = new int [d];
		for(int i = 0;i<d;i++){ //?°??????\?????????
			niti[i] = sc.nextInt();
		}
		for(int i = 0;i < n;i++){
			low[i] = sc.nextInt();
			high[i] = sc.nextInt();
			point[i] = sc.nextInt();
		}
		for(int i = 0;i < d;i++){ //????????? ????????????for??§??\????????????
			for(int m = 0;m < n;m++){//????????????????????????for??§????????????
				if(low[m]<=niti[i]&&niti[i]<=high[m]){//???????°?????????¶????????????
					select[i][count] = point[m];
					count++;
				}
			}
			huku [i] = count;
			count = 0; //?????????
		}
		for(int i = 0;i<d;i++){
			for(int m = 0; m < huku[i];m++){
				//System.out.print(select[i][m]+" ");
			}
			//System.out.println();
		}
		//?????????????????????
		//?????????????´???????????±??????????
		int max[] = new int [d];//??\?????¨????????§?´????????????????
		int min[] = new int [d];//??\?????¨??????????´????????????????
		for(int i = 0;i<d;i++){ //??\????????????
			max[i] = select[i][0];
			min[i] = select[i][0];
			for(int m = 0;m < huku[i];m++){ // ?????????????????????
				if(min[i] > select[i][m]){
					min[i] = select[i][m];
				}
				else if(max[i] < select[i][m]){
					max[i] = select[i][m];
				}
			}
			//System.out.print(i+"?????§???"+max[i]);
			//System.out.println("  ????°????"+min[i]);
		}
		int x;
		int y;
		int z;
		int v;
		int start1 = 0;
		int start2 = 0;
		int start3 = 0;
		int start4 = 0;
		int box1 = max[0];//42
		int box2 = min[0];//19
		int box3 = max[0];//42
		int box4 = min[0];//19
		for(int i = 1;i<d;i++){
			x = Math.abs(max[i]-box1);
			//System.out.println("??????"+x);
			if(i%2==1){
				y = Math.abs(max[i]-box2);
				//System.out.println("??????"+y);
			}
			else{
				y = Math.abs(min[i]-box2);
				//System.out.println("??????"+y);
			}
			if(i%2==1){
				z = Math.abs(min[i]-box3);
				//System.out.println("??????"+z);
			}
			else{
				z = Math.abs(max[i]-box3);
				//System.out.println("??????"+z);
			}
			v = Math.abs(min[i]-box4);
			//System.out.println("??????"+v);
			start1 = start1 + x;
			start2 = start2 + y;
			start3 = start3 + z;
			start4 = start4 + v;
			/*System.out.println(i+"??±?????????");
			System.out.println("??????1???"+start1);
			System.out.println("??????2???"+start2);
			System.out.println("??????3???"+start3);
			System.out.println("??????4???"+start4);*/
			if(box1!=box3){
				if(start1<start3){
					start1 = start3;
				}
				else{
					start3 = start1;
				}
			}
			else if(box1!=box2){
				if(start1<start2){
					start1 = start2;
				}
				else{
					start2 = start1;
				}
				
			}
			else if(box1!=box4){
				if(start1<start4){
					start1 = start4;
				}
				else{
					start4 = start1;
				}
				
			}
			else if(box2!=box3){
				if(start2<start3){
					start2 = start3;
				}
				else{
					start3 = start2;
				}
				
			}
			else if(box2!=box4){
				if(start2<start4){
					start2 = start4;
				}
				else{
					start4 = start2;
				}
				
			}
			else if(box3!=box4){
				if(start3<start4){
					start3 = start4;
				}
				else{
					start4 = start3;
				}
				
			}
			box1 = max[i];
			if(i%2==1){
				box2 = max[i];
			}
			else{
				box2 = min[i];
			}
			if(i%2==1){
				box3 = min[i];
			}
			else{
				box3 = max[i];
			}
			box4 = min[i];
			/*System.out.println(i+"??±?????´????????????");
			System.out.println("??????1???"+start1);
			System.out.println("??????2???"+start2);
			System.out.println("??????3???"+start3);
			System.out.println("??????4???"+start4);*/
		}
		/*System.out.println(start1);
		System.out.println(start2);
		System.out.println(start3);
		System.out.println(start4);*/
		int result [] = new int [5];
		result[0] = start1;
		result[1] = start2;
		result[2] = start3;
		result[3] = start4;
		result[4] = 0;
		for(int i = 0;i<4;i++){
			if(result[4] < result[i]){
				result[4] = result[i];
			}
		}
		System.out.println(result[4]);
	}
}

Measured memory_bytes: 21108