#include <iostream>
#include <vector>
#include <cstring>
#include <map>
using namespace std;
void fun(multimap<int, int> &Map, vector<double> &useTime, vector<int>& path,
vector<vector<int> > &paths, int key, int &time, int &maxTime) {
multimap<int, int>::iterator iter;
time += useTime[key];
path.push_back(key);
if ((iter = Map.find(key)) != Map.end()) {
int n = Map.count(key);
for (int j = 0; j < n; ++j, ++iter) {
fun(Map, useTime, path, paths, iter->second, time, maxTime);
}
} else {
paths.push_back(path);
if (maxTime < time)
maxTime = time;
}
time -= useTime[key];
path.pop_back();
}
int main()
{
int m, n;
cin >> m >> n;
vector<double> useTime(m+1);
bool* isRoot = new bool[m + 1];
memset(isRoot, 1, m + 1);
multimap<int, int> Map;
int maxTime = 0;
vector<vector<int> > paths;
for (int i=1; i<=m; ++i) {
double time;
cin >> time;
useTime[i] = time;
}
for (int i=0; i<n; ++i) {
int father, son;
cin >> father >> son;
Map.insert(make_pair(father, son));
isRoot[son] = false;
}
for (int i=1; i<=m; ++i) {
if (isRoot[i]) {
int time = 0;
vector<int> path;
fun(Map, useTime, path, paths, i, time, maxTime);
}
}
delete[] isRoot;
cout << paths.size() << " " << maxTime << endl;
return 0;
}