#include <bits/stdc++.h>

using namespace std;

int t[200];
int a[200], b[200], c[200];

int dp[200][200];

int main()
{
    int d, n; 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];
    }

    for (int i = 1; i < d; ++i) {
        for (int j = 0; j < n; ++j) { // i??\???
            if (a[j] <= t[i] && t[i] <= b[j]) {
                for (int k = 0; k < n; ++k) {
                    if (a[k] <= t[i - 1] && t[i - 1] <= b[k]) {
                        dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(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);
}