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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(int &a, int b) { if (a > b) a = b; }
void chmax(int &a, int b) { if (a < b) a = b; }

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> value(N);
	FOR(i,0,N){
		cin >> value.at(i);
	}
	vector<vector<int>> data(N);
	FOR(i,0,M){
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		data.at(y).push_back(x);
	}

	int ans = -2e9;

	FOR(i,0,N){
		if(data.at(i).size()==0){
			continue;
		}
		int nowvalue = value.at(i);
		FOR(j,0,data.at(i).size()){
			int now = data.at(i).at(j);
			chmin(value.at(i), value.at(now));
			ans = max(ans, nowvalue - value.at(now));
		}
	}

	cout << ans << endl;

	return 0;
}


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

int n, m;
vector<long long> a;

int solve();

int main() {
  cin >> n >> m;
  a.resize(m);
  for (int i = 0; i < m; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  long long res = 0, len = 3e9;
  a.push_back(0);
  a.push_back(n + 1);
  sort(a.begin(), a.end());
  n = a.size();
  for (int i = 1; i < n; ++i)
    if (a[i] - a[i - 1] - 1) len = min(len, a[i] - a[i - 1] - 1);
  if (len == 3e9) return 0;
  for (int i = 1; i < n; ++i) res += (a[i] - a[i - 1] - 1 + len - 1) / len;
  return res;
}