#include <bits/stdc++.h>
inline long long read() {
  long long x = 0;
  char ch = getchar(), w = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * w;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
using namespace std;
const int N = 6100;
int a[N], n;
vector<int> g[N];
int f[N];
int ans;
void dfs(int x, int F) {
  int pos = lower_bound(f + 1, f + 1 + n, a[x]) - f;
  int tmp = f[pos];
  f[pos] = a[x];
  int t = lower_bound(f + 1, f + 1 + n, 0x3f3f3f3f) - f - 1;
  ans = max(ans, t);
  for (int y : g[x])
    if (y != F) {
      dfs(y, x);
    }
  f[pos] = tmp;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i < n; ++i) {
    int x = read(), y = read();
    g[x].push_back(y);
    g[y].push_back(x);
  }
  memset(f, 0x3f, sizeof f);
  for (int i = 1; i <= n; ++i) {
    dfs(i, 0);
  }
  writeln(ans);
  return 0;
}
