#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL A,B; cin >> A >> B;
    if(A == B){
        REP(i,A){
            cout << 1+i << " ";
        }

        REP(i,B){
            cout << -1-i << " ";
        }
        cout << endl;


    }else if(A > B){

        REP(i,A){
            cout << 1+i << " ";
        }

        REP(i,B-1){
            cout << -1-i << " ";
        }
        cout << -((A+B) * (A-B+1) / 2) << " ";
        cout << endl;

    }else{

        REP(i,A-1){
            cout << 1+i << " ";
        }

        cout << ((A+B) * (B-A+1) / 2) << " ";
        REP(i,B){
            cout << -1-i << " ";
        }
        cout << endl;


    }

}
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define rng(i,l,r) for (int i=l; i<r; i++)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> using V = vector<T>;
template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
struct in { template <class T> operator T() { T t; std::cin >> t; return t; } };
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int dy[8] = {1,0,-1,0,1,-1,1,-1};
using Graph = V<V<int>>;
auto solve() {
   int n = in();
   int m = in();
   Graph G(n);
   vector<int> a(n); rep(i,n) cin >> a[i];
   rep(i,m) {
      int x=in(), y=in();
      G[x-1].push_back(y-1);
   }
   auto cmp = [&a](int i, int j) { return a[i] < a[j]; };
   V<int> idx(n); rep(i,n) idx[i] = i;
   sort(all(idx), cmp);

   vector<int> seen(n, 0);
   int ans = -INF;
   for (auto i : idx) {
      if (seen[i]) continue;
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
         int v = q.front(); q.pop();
         if (v != i) chmax(ans, a[v] - a[i]);
         for (auto u : G[v]) {
            if (seen[u]) continue;
            seen[u] = 1;
            q.push(u);
         }
      }
   }
   return ans;
}

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);

   cout << solve() << endl;
}
