#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

int D, N;
int T[256];
int A[256], B[256], C[256];
int memo[256][256];

int dfs(int day, int b) {
  if (day == D) return 0;
  if (memo[day][b] != -1) return memo[day][b];

  int &res = memo[day][b];
  for (int i = 0; i < N; ++i) {
    if (A[i] <= T[day] && T[day] <= B[i]) {
      res = max(res, dfs(day + 1, C[i]) + abs(b - C[i]));
    }
  }

  return res;
}

int main() {
  cin >> D >> N;
  for (int i = 0; i < D; ++i) cin >> T[i];
  for (int i = 0; i < N; ++i) cin >> A[i] >> B[i] >> C[i];
  memset(memo, -1, sizeof(memo));

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] <= T[0] && T[0] <= B[i]) {
      ans = max(ans, dfs(1, C[i]));
    }
  }
  cout << ans << endl;

  return 0;
}