#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const long long INF64 = 9e18;
const long double EPS = 1e-9;
const long double PI = 3.14159265358979310000;
const long long MD = 535355424;
const long long T = 34539;
const int N = 300001;
const int M = 301;
int n, a[N], d[N], first, second, k = 0;
bool mark[N];
vector<pair<int, int> > g[N];
int dfs(int v, int p, int pos, int vv) {
  int s = 0;
  if (a[v] > a[vv]) {
    int ss = 0;
    for (int i = 0; i < int(int((g[v]).size())); i++)
      if (g[v][i].first != p) {
        if (!mark[g[v][i].second]) {
          d[g[v][i].second] = dfs(g[v][i].first, v, g[v][i].second, v) + 1;
          mark[g[v][i].second] = 1;
          ss = max(ss, d[g[v][i].second] - 1);
        } else
          ss = max(ss, d[g[v][i].second] - 1);
      }
    s = ss + 1;
  }
  for (int i = 0; i < int(int((g[v]).size())); i++)
    if (g[v][i].first != p)
      s = max(s, dfs(g[v][i].first, v, g[v][i].second, vv));
  return s;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < int(n - 1); i++) {
    scanf("%d %d", &first, &second);
    if (first > second) swap(first, second);
    k++;
    g[first].push_back(make_pair(second, k));
    k++;
    g[second].push_back(make_pair(first, k));
  }
  for (int v = 1; v <= n; v++)
    for (int i = 0; i < int(int((g[v]).size())); i++)
      if (!mark[g[v][i].second]) {
        d[g[v][i].second] = dfs(g[v][i].first, v, g[v][i].second, v) + 1;
        mark[g[v][i].second] = 1;
      }
  int maxi = 0;
  for (int i = 1; i <= k; i++) maxi = max(maxi, d[i]);
  cout << maxi;
  return 0;
}
