#include<iostream>
#include<cstdlib>

int D, N;
int T[200];
int A[200], B[200], C[200];
bool suit[200][200];
int dp[200][200];

int main()
{
	std::cin >> D >> N;
	for( int i = 0; i != D; ++i )
		std::cin >> T[i];
	for( int i = 0; i != N; ++i )
		std::cin >> A[i] >> B[i] >> C[i];

	for( int i = 0; i != D; ++i )
		for( int j = 0; j != N; ++j )
			suit[i][j] = A[j] <= T[i] && T[i] <= B[j];

	for( int i = 0; i != D - 1; ++i )
		for( int j = 0; j != N; ++j )
			if( suit[i+1][j] )
				for( int k = 0; k != N; ++k )
					if( suit[i][k] )
						dp[i+1][j] = std::max( dp[i+1][j], dp[i][k] + abs( C[j] - C[k] ) );

	int ans = 0;
	for( int i = 0; i != N; ++i )
		ans = std::max( ans, dp[D-1][i] );

	std::cout << ans << std::endl;

	return 0;
}