#include <bits/stdc++.h>
using namespace std;
const int maxn = 50000;
const long long MODD = 1000000007;
const long double eps = 1E-9;
vector<vector<int> > tree;
vector<int> a;
vector<int> d;
int curanswer = 1;
void dfs(int v, int root = -1) {
  int j = int(upper_bound(d.begin(), d.end(), a[v]) - d.begin());
  int was = d[j];
  if (d[j - 1] < a[v] && a[v] < d[j]) {
    d[j] = a[v];
    curanswer = max(curanswer, j);
  }
  for (int i = 0; i < tree[v].size(); i++) {
    if (tree[v][i] == root) continue;
    dfs(tree[v][i], v);
  }
  d[j] = was;
}
int main() {
  int n;
  cin >> n;
  tree.resize(n);
  a.resize(n);
  d.resize(n + 1, 1000000000);
  d[0] = -1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    dfs(i);
  }
  cout << curanswer << endl;
  return 0;
}
