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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int D = next<int>(), N = next<int>();
    auto T = next<vector<int>>(D);
    vector<vector<int>> c(D);
    times(N, j) {
        int A = next<int>(), B = next<int>(), C = next<int>();
        times(D, i) {
            if(A <= T[i] && T[i] <= B) c[i].push_back(C);
        }
    }
    int ans_max, before_max, ans_min, before_min;
    times(D, i) {
        int a = min(c[i]), b = max(c[i]);
        if(i) {
            int ans_min_tmp = ans_min;
            ans_min = max(ans_min + abs(a - before_min), ans_max + abs(a - before_max));
            ans_max = max(ans_min_tmp + abs(b - before_min), ans_max + abs(b - before_max));
            before_min = a;
            before_max = b;
        } else {
            ans_max = ans_min = 0;
            before_min = a;
            before_max = b;
        }
        #ifdef debug
            cout << "[" << a << "," << b << "] " << ans_min << " " << ans_max ln;
        #endif
    }
    cout << max(ans_min, ans_max) ln;

    return 0;
}

Measured memory_bytes: 1324