#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long
#define P 3030
#define N 400100
#define M 1000100
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
int ins[N] , ver[M] , l[N] , head[N] , next[M] , n , m ;
int stack[N] , top , low[N] , dfn[N] , hc[N] , nc[M] , vc[M];
int c[N] , lc[N] , Max[N] , cnt , tot , num ,tc , d[N] , f[N] , fm[N];
int ans , Mans;
void add(int x , int y){
ver[++tot] = y ; next[tot] = head[x] , head[x] = tot;
}
void add_c(int x , int y){
vc[++tc] = y , nc[tc] = hc[x] , hc[x] = tc; d[y]++;
}
void tarjan(int x){
dfn[x] = low[x] = ++num; ins[x] = 1;
stack[++top] = x; int y;
for (int i = head[x] ; i ; i = next[i]){
if (!dfn[y = ver[i]]) {
tarjan(y); low[x] = min(low[x] , low[y]);
}
else if (ins[y]) low[x] = min(low[x] , dfn[y]);
}
if (low[x] == dfn[x]){
cnt++ ;
do{
y = stack[top--] , ins[y] = 0 ;
c[y] = cnt; lc[cnt] += l[y];
Max[cnt] = max(Max[cnt] , l[y]);
}while(x != y);
}
}
void dfs(int x){
f[x] = 0 , fm[0] = 0;
for (int i = hc[x] ; i ; i = nc[i]){
int y = vc[i];
dfs(y);
if (f[x] == f[y]){
fm[x] = max(fm[x] , fm[y]);
}
if (f[x] < f[y]) {
f[x] = f[y];
fm[x] = fm[y];
}
}
fm[x] = max(Max[x] , fm[x]);
f[x] += lc[x];
}
int main(){
freopen("c.txt" , "r" , stdin);
freopen("c.out" , "w" , stdout);
scanf("%d%d" , &n ,&m);
for (int i = 1 ; i <= n ; ++i){
scanf("%d" , l + i);
}
for (int i = 1 ; i <= m ; ++i){
int x , y;
scanf("%d%d" , &x , &y);
add(x , y);
}
for (int i = 1 ; i <= n ; ++i){
if (!dfn[i]) tarjan(i);
}
for (int x = 1 ; x <= n ; ++x){
for (int i = head[x] ; i ; i = next[i]){
if (c[x] == c[ver[i]]) continue;
add_c(c[x] , c[ver[i]]);
}
}
for (int i = 1 ; i <= cnt ; ++i){
if (!d[i]){
dfs(i);
if (f[i] == ans){
Mans = max(Mans , fm[i]);
}
if (f[i] > ans){
ans = f[i] ; Mans = fm[i];
}
}
}
printf("%d %d" , ans , Mans);
return 0;
}