#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <array>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
struct BigInt{
static constexpr ll DIGITS = 30;
static constexpr ll BASE = 1 << DIGITS;
vector<ll> digits;
BigInt(){}
BigInt(int x){
digits = {x};
}
friend BigInt operator+(const BigInt &l, const BigInt &r){
BigInt result;
result.digits.clear();
ll carry = 0;
for(int i = 0; i < max(l.digits.size(), r.digits.size()); ++i){
ll a = 0, b = 0;
if(i < l.digits.size()) a = l.digits[i];
if(i < r.digits.size()) b = r.digits[i];
carry += a + b;
result.digits.push_back(carry % BASE);
carry /= BASE;
}
if(carry){
result.digits.push_back(carry);
}
return result;
}
int count_digits(){
assert(!digits.empty());
int count = (int)(digits.size()) - 1;
count *= DIGITS;
if(digits.back() == 0){
return 0;
}
ll leading_digit = digits.back();
while(leading_digit){
leading_digit /= 2;
++count;
}
return count;
}
};
const int N = 1e4 + 3;
const int M = 1e5 + 3;
int n, m, leaf;
int a[N];
vector<int> adj[N];
BigInt dp[N];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
cin >> a[i];
dp[i] = BigInt(a[i]);
}
for(int i = 1; i <= m; ++i){
int x, y;
cin >> x >> y;
adj[x].push_back(y);
}
for(int i = 1; i <= n; ++i){
if(adj[i].empty()){
leaf = i;
}
}
static int cnt_pointing[N];
for(int i = 1; i <= n; ++i){
for(int to: adj[i]){
++cnt_pointing[to];
}
}
queue<int> q;
for(int i = 1; i <= n; ++i)
if(!cnt_pointing[i]){
q.push(i);
}
while(!q.empty()){
int u = q.front();
q.pop();
// cout << u << " u" << endl;
for(int to: adj[u]){
dp[to] = dp[to] + dp[u] + dp[u];
--cnt_pointing[to];
if(!cnt_pointing[to]){
q.push(to);
}
}
}
cout << dp[leaf].count_digits() << "\n";
}