#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int MaxN = int(2e5) + 256;
const int MOD = int(1e9) + 7;
template <typename T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
inline bool Palindrome(const string& s) {
  return equal(s.begin(), s.end(), s.rbegin());
}
int n;
vector<int> g[MaxN];
int r[MaxN], d[MaxN];
int cur;
void f(int v, int p = -1) {
  for (auto to : g[v])
    if (to != p) {
      int w = r[to], j = upper_bound(d, d + n + 1, w) - d;
      int old = d[j];
      if (d[j - 1] < w && w < d[j]) {
        d[j] = w;
        cur = max(cur, j);
      }
      f(to, v);
      d[j] = old;
    }
}
inline void run(int v) {
  cur = 1;
  d[1] = r[v];
  f(v);
  d[1] = INT_MAX;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", r + i);
  fill(d, d + n + 1, INT_MAX);
  d[0] = -INT_MAX;
  for (int i = 1; i < n; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    g[v].push_back(u);
    g[u].push_back(v);
  }
  int res = 1;
  for (int v = 1; v <= n; ++v) {
    run(v);
    res = max(res, cur);
  }
  printf("%d", res);
  return 0;
}
