#include <vector>
#include <algorithm>
#include <iostream>
#include <climits>

using namespace std;

#define rep(i,n) for(int i=0;i<n;++i)
#define fep(i,j,n) for(int i=j;i<n;++i)
#define ll long long 
#define ay array
#define vtc vector
#define MN 200001


vtc<int> dag;
vtc<int> v[MN];
int val[MN];
int dp[MN];
bool done[MN];

void dfs(int i){
    if(done[i])return;
    done[i]=1;
    for(int j:v[i])
        dfs(j);
    dag.push_back(i);
}

int main(){
    int n,m;
    cin >>n>>m;
    rep(i,n)
        cin >>val[i];

    rep(i,m){
        int a,b;
        cin >>a>>b;
        a--;b--;
        v[a].push_back(b);
    }

    rep(i,n){
        dfs(i);
        dp[i]=INT_MAX;
    }
    
    reverse(dag.begin(),dag.end());
    int sol=INT_MIN;

    for(int c:dag){
        dp[c]=min(dp[c],val[c]);
        for(int t:v[c]){
            dp[t]=min(dp[t],dp[c]); 
            sol=max(sol,val[t]-dp[t]);
        }
    }
    cout <<sol<<endl;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <climits>
#include <set>
#include <cstring>
#include <unordered_map>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <stdlib.h>
#include <chrono>
 
///////////////////////////////////////////////////////////////////////////////////////////////////
#define fio  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll  long long int
#define ull unsigned long long int
#define cinll(x) ll x;cin >> x;
#define cini(x) int x;cin >> x;
#define cins(x) string x;cin >> x;
#define vect(x) vector<ll> x
#define vect1(x) vector<ll> x;x.push_back(0);
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
///////////////////////////////////////////////////////////////////////////////////////////////////
#define MAX 1e17
#define MIN -9223372036854775800
#define MOD 1000000007
#define f first
#define s second
///////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
using u64 = uint64_t;
//Safe_hashing for minimising collisions 
//https://codeforces.com/blog/entry/62393
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
bool compare(pair<string,ll> a,pair<string,ll> b) {
    return a.s > b.s;
} 

void findAns(map<ll,char> & mapit,ll currPin,ll & ans,vector<ll> &pin) {
    if(currPin == 5) {
        bool ok = true;
        for(ll i = 0;i <= 9;i++) {
            if(mapit[i] == 'o') {
                bool search = false;
                for(ll j = 1;j <= 4;j++) {
                    if(pin[j] == i) search = true;
                }
                if(search == false) {
                    ok = search;
                    break;
                }
            }
        }
        if(ok) {
            ans++;
        }    
        return;
    }
    for(ll i = 0;i <= 9;i++) {
        if(mapit[i] == 'o' || mapit[i] == '?') {
            pin[currPin] = i;
            findAns(mapit,currPin+1,ans,pin);
            pin[currPin] = 0;
        }
    }
}
 
void solve() {
    map<ll,char> mapit;
    for(ll i=0;i<10;i++) {
        char ch;
        cin>>ch;
        mapit[i] = ch;
    }
    ll ans = 0;
    vector<ll> pin(5,0);
    findAns(mapit,1,ans,pin);
    cout<<ans;
    return;
} 
 
int main(){
    // fio;
    // cinll(t);
///////////////////////////////////////////    
    #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r", stdin);
    freopen("output.txt", "w" , stdout);
    #endif
///////////////////////////////////////////
    // cinll(t);
    // for(ll i=1;i<=t;i++) {
        solve();
    // }
  return 0;
}