#include <bits/stdc++.h>
using namespace std;
long long ct[500], s[251000], c[251000], f[251000], r[251000], n, m;
bool f2(long long id, long long t) {
  long long i = s[id] - 1, comb = t, disp = r[id];
  for (; i < n && i < f[id] - 1; i++) {
    if (c[id] * (ct[i + 1] - ct[i]) > comb) disp--, comb = t;
    if (c[id] * (ct[i + 1] - ct[i]) > t) return 0;
    comb -= c[id] * (ct[i + 1] - ct[i]);
  }
  return disp >= 0;
}
int p[251000];
int main() {
  ios_base::sync_with_stdio(false), std::cin.tie(NULL);
  mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> ct[i];
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> f[i] >> c[i] >> r[i];
    p[i] = i;
  }
  shuffle(p, p + m, rng);
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    if (f2(p[i], ans)) continue;
    long long l2 = ans, r2 = 1e18;
    while (l2 < r2) {
      long long mid = (l2 + r2) / 2;
      if (f2(p[i], mid))
        r2 = mid;
      else
        l2 = mid + 1;
    }
    while (l2) {
      if (f2(p[i], l2)) break;
      l2--;
    }
    ans = l2;
  }
  cout << ans << endl;
}
