#include <bits/stdc++.h>
using namespace std;
struct node {
  int ok, p, x;
  node() {}
  node(int _ok, int _p, int _x) {
    ok = _ok;
    p = _p;
    x = _x;
  }
};
int n, k, a[8000], b[8000], ans, v[8000], d[8000];
vector<int> edge[8000];
node insert(int x) {
  if (k == 0 || x > b[k - 1]) {
    b[k++] = x;
    if (k > ans) ans = k;
    return node(1, k, 0);
  }
  int l, r, mid;
  l = 0;
  r = k - 1;
  while (l < r) {
    mid = (l + r) / 2;
    if (x == b[mid]) return node(0, 0, 0);
    if (x > b[mid])
      l = mid + 1;
    else
      r = mid;
  }
  int t = b[l];
  b[l] = x;
  return node(1, l, t);
}
void read() {
  int i, x, y;
  memset(d, 0, sizeof(d));
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    d[i] = 0;
    edge[i].clear();
  }
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    edge[x].push_back(y);
    edge[y].push_back(x);
    d[x]++;
    d[y]++;
  }
}
void dfs(int x) {
  int i;
  node r;
  v[x] = 1;
  r = insert(a[x]);
  for (i = 0; i < edge[x].size(); i++)
    if (!v[edge[x][i]]) dfs(edge[x][i]);
  if (r.ok) {
    b[r.p] = r.x;
    if (r.x == 0) k--;
  }
}
void work() {
  int i;
  ans = 0;
  for (i = 1; i <= n; i++)
    if (d[i] == 1) {
      memset(v, 0, sizeof(v));
      memset(b, 0, sizeof(b));
      k = 0;
      dfs(i);
    }
  printf("%d\n", ans);
}
int main() {
  while (scanf("%d", &n) == 1) {
    read();
    work();
  }
  return 0;
}
