#include typedef long long ll; const int maxn = 2e5 + 3; int n, m, x[maxn]; ll a[maxn], w[maxn]; ll ceildiv(ll a, ll b) { return a % b ? a / b + 1 : a / b; } ll pt[maxn][2]; bool check(ll c) { if(c <= 0) { return std::accumulate(w, w + m, 0ll) <= *std::min_element(a + 1, a + n + 1); } for(int i = 1; i <= n + 1; ++i) pt[i][0] = pt[i][1] = 0; for(int j = 0; j < m; ++j) { ll u = w[j] / c + x[j]; ll v = x[j] - w[j] / c; pt[std::max(1ll, v)][0] += c; pt[std::max(1ll, v)][1] += w[j] - c * x[j]; pt[x[j]][0] += -c - c; pt[x[j]][1] += w[j] + c * x[j] - (w[j] - c * x[j]); pt[std::min(n + 1ll, u + 1)][0] += c; pt[std::min(n + 1ll, u + 1)][1] += -(w[j] + c * x[j]); } ll u = 0, v = 0; for(int i = 1; i <= n; ++i) { u += pt[i][0]; v += pt[i][1]; if(u * (ll)i + v >= a[i]) return false; } return true; } int main() { scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%lld", a + i); for(int i = 0; i < m; ++i) scanf("%d%lld", x + i, w + i); ll l = -1, r = 1e10; while(r - l > 1) { ll mid = (l + r) / 2; if(check(mid)) r = mid; else l = mid; } printf("%lld\n", r < 1e10 ? r : -1); return 0; }