#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
map<int, vector<pair<int, int> > > e;
const int NMAX = 410000;
int l[NMAX], r[NMAX], t[NMAX];
pair<int, int> b[NMAX];
long long ans[NMAX];
int main() {
  int n, m;
  scanf("%d%d", &m, &n);
  for (int i = 0; i < (int)(n); i++) scanf("%d%d%d", &l[i], &r[i], &t[i]);
  for (int i = 0; i < (int)(n); i++) {
    e[r[i]].push_back(make_pair(+1, i));
    e[l[i]].push_back(make_pair(-1, i));
  }
  set<pair<int, int> > q;
  vector<pair<int, int> > f;
  vector<int> ll;
  int cnt = 0;
  for (map<int, vector<pair<int, int> > >::iterator it = --e.end();; it--) {
    vector<pair<int, int> >& v = it->second;
    for (int i = 0; i < (int)(v.size()); i++) {
      int id = v[i].second;
      if (v[i].first == -1) q.erase(make_pair(t[id], id));
    }
    for (int i = 0; i < (int)(v.size()); i++) {
      int id = v[i].second;
      if (v[i].first == +1) q.insert(make_pair(t[id], id));
    }
    if (!q.empty()) {
      map<int, vector<pair<int, int> > >::iterator cp(it);
      if (cp == e.begin()) throw;
      cp--;
      ll.push_back(q.begin()->first - it->first);
      f.push_back(make_pair(q.begin()->first - it->first, cnt));
      f.push_back(make_pair(q.begin()->first - cp->first, cnt));
      cnt++;
    }
    if (it == e.begin()) break;
  }
  sort(f.begin(), f.end());
  vector<char> was(cnt);
  for (int i = 0; i < (int)(m); i++) {
    scanf("%d", &b[i].first);
    b[i].second = i;
  }
  sort(b, b + m);
  long long len = 0, sum = 0, k = 0;
  int ptr = 0;
  for (int i = 0; i < (int)(m); i++) {
    while (ptr < (int)f.size() && f[ptr].first <= b[i].first) {
      int id = f[ptr].second;
      if (was[id]) {
        len += f[ptr].first - ll[id];
        sum -= ll[id];
        k--;
      } else {
        sum += ll[id];
        k++;
        was[id] = true;
      }
      ptr++;
    }
    ans[b[i].second] = len + k * b[i].first - sum;
  }
  for (int i = 0; i < (int)(m); i++) printf("%I64d\n", ans[i]);
  return 0;
}
