#include <bits/stdc++.h>
using namespace std;

constexpr int INF = 1e9;

int main() {
    int D, N; cin >> D >> N;
    vector<int> T(D), A(N), B(N), C(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];
    }

    vector<vector<int>> dp(D + 1, vector<int>(N, -INF));
    for(int i = 0; i < D; ++i) {
        for(int j = 0; j < N; ++j) {
            if(A[j] <= T[i] && T[i] <= B[j]) {
                if(i == 0) {
                    dp[i + 1][j] = 0;
                } else {
                    for(int k = 0; k < N; ++k) {
                        dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abs(C[j] - C[k]));
                    }
                }
            }
        }
    }

    cout << *max_element(begin(dp[D]), end(dp[D])) << endl;
}

