#include <bits/stdc++.h>
using namespace std;
struct wall {
  int no, x, t;
  friend bool operator<(wall a, wall b) {
    if (a.x != b.x) return a.x < b.x;
    return a.t < b.t;
  }
} w[110000 << 1];
struct Point {
  int x, y, type, no;
  friend bool operator<(Point a, Point b) { return a.y - a.x < b.y - b.x; }
} p[110000 * 5];
int tot;
int L[110000], R[110000], T[110000];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
bool vis[110000];
int ans[110000];
int main() {
  register int n, m, i, k, now, cnt;
  scanf("%d%d", &m, &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", L + i, R + i, T + i);
    w[i << 1].no = w[i << 1 | 1].no = i;
    w[i << 1].x = L[i], w[i << 1 | 1].x = R[i];
    w[i << 1].t = w[i << 1 | 1].t = T[i];
  }
  sort(w + 2, w + n + n + 2);
  q.push(pair<int, int>(0x7f7f7f7f, 0));
  vis[0] = 1;
  for (i = 2; i <= n + n + 1; i++) {
    if (!vis[w[i].no]) {
      while (!q.empty() && !vis[q.top().second]) q.pop();
      if (!q.empty() && w[i].t < q.top().first) {
        tot++;
        p[tot].x = w[i].x;
        p[tot].y = q.top().first;
        p[tot].type = 1;
        tot++;
        p[tot].x = w[i].x;
        p[tot].y = w[i].t;
        p[tot].type = -1;
      }
      q.push(pair<int, int>(w[i].t, w[i].no));
      vis[w[i].no] = 1;
    } else {
      while (!q.empty() && !vis[q.top().second]) q.pop();
      if (q.top().second == w[i].no) {
        q.pop();
        while (!q.empty() && !vis[q.top().second]) q.pop();
        tot++;
        p[tot].x = w[i].x;
        p[tot].y = w[i].t;
        p[tot].type = 1;
        tot++;
        p[tot].x = w[i].x;
        p[tot].y = q.top().first;
        p[tot].type = -1;
      }
      vis[w[i].no] = 0;
    }
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &k);
    tot++;
    p[tot].type = 0;
    p[tot].x = 0;
    p[tot].y = k;
    p[tot].no = i;
  }
  sort(p + 1, p + tot + 1);
  for (i = 1, now = 0, cnt = 0; i <= tot; i++) {
    now += cnt * (p[i].y - p[i].x - p[i - 1].y + p[i - 1].x);
    cnt += p[i].type;
    if (!p[i].type) ans[p[i].no] = now;
  }
  for (i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
