#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
vector<int> side[N];
int a[N],na[N];
//point's weight
int n,m;
int epoch[N],t;
set<pair<int,int>>mp;
vector<int> side2[N];
void nside(){
for(int i=1;i<=n;++i)
for(auto &j:side[i])
if(epoch[i]!=epoch[j] && mp.find({epoch[i],epoch[j]})==mp.end()){
side2[epoch[i]].push_back(epoch[j]);
mp.insert({epoch[i],epoch[j]});
}
for(int i=1;i<=n;++i)
na[epoch[i]]+=a[i];
return;
}
void dfs(int x){
epoch[x]=++t;
for(auto &i:side[x]){
if(!epoch[i])dfs(i);
epoch[x]=min(epoch[x],epoch[i]);
}
t--;
return;
}
void dfs2(int x){
int c=0;
for(auto &i:side2[x]){
dfs2(i);
c=max(c,na[i]);
}
na[x]+=c;
return;
}
void work(){
cin>>n>>m;
for(int i=1;i<=n;++i)
cin>>a[i];
for(int i=1;i<=m;++i){
int x,y;cin>>x>>y;
side[x].push_back(y);
}
for(int i=1;i<=n;++i)
if(!epoch[i])dfs(i);
//some point won't be dfsed because maybe m<n
//there is not a complete tree
nside();
//max
for(int i=1;i<=n;++i)
dfs2(i);
int ans=0;
for(int i=1;i<=n;++i)
ans=max(ans,na[i]);
cout<<ans;
return;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _=1;
while(_--)work();
PROCESS_MEMORY_COUNTERS pmc1;
return 0;
}