#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll,ll>>>
#define vpl vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define pb push_back
#define se second
#define fi first
#define all(v) v.begin(),v.end()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

using namespace std;

template<typename T> istream& operator>>(istream&i,v(T)&v){rep(j,v.size())i>>v[j];return i;}
template<typename T> string join(const v(T)&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T> ostream& operator<<(ostream&o,const v(T)&v){if(v.size())o<<join(v);return o;}



using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

const ll mod = 1e9 + 7; //998244353;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll modpow(ll a,ll b){
    if(b == 0){
        return 1;
    }
    if(b%2 == 0){
        ll tmp = modpow(a,b/2);
        return tmp*tmp%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }

}

vvl g;
vl a;
bool done[1000000];
ll dp[1000000];
ll dfs(ll x){
    if(done[x])return dp[x];
    done[x] = true;
    ll num = -INF;
    for(ll k : g[x]){
        ll tmp = max(a[k],dfs(k));
        chmax(num,tmp);
    }
    return dp[x] = num;
}



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    g.resize(n);
    a.resize(n);
    cin >> a;
    rep(i,m){
        int x,y;
        cin >> x >> y;
        --x;--y;
        g[x].pb(y);
    }
    ll ans = -INF;
    rep(i,n){
        ll benefit = dfs(i)-a[i];
        chmax(ans,benefit);
    }

    cout << ans << endl;
    

    return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int L, R;
ll cnt[1010101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> L >> R;

	rrep(g, 1010100, 2) {
		cnt[g] = 1LL * (R / g - (L - 1) / g) * (R / g - (L - 1) / g);
		int x = 2 * g;
		while (x <= R) {
			cnt[g] -= cnt[x];
			x += g;
		}
	}

	ll ans = 0;
	rep(g, 2, 1010101) {
		ans += cnt[g]; 
		if (L <= g && g <= R) {
			ans -= R / g - (L - 1) / g;
			ans -= R / g - (L - 1) / g;
			ans++;
		}
	}
	cout << ans << endl;
}





