#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int popcount(T t) {
  if (std::numeric_limits<T>::digits <=
      std::numeric_limits<unsigned int>::digits) {
    return __builtin_popcount(t);
  } else {
    return __builtin_popcountll(t);
  }
}
const long double EPS = 1e-8;
const long double PI = acosl(0.0) * 2;
pair<int, int> update(int* a, int& n, int x) {
  long long i = distance(a, lower_bound(a, a + n, x));
  if (i < n) {
    pair<int, int> ret(i, a[i]);
    a[i] = x;
    return ret;
  } else {
    pair<int, int> ret(n, 0);
    a[n++] = x;
    return ret;
  }
}
int dfs(int v, int p, const vector<int>& r, const vector<vector<int> >& g,
        int* buffer, int n) {
  int ret = n;
  for (int u : g[v]) {
    if (u == p) continue;
    int m = n;
    pair<int, int> up = update(buffer, m, r[u]);
    ret = max(ret, dfs(u, v, r, g, buffer, m));
    buffer[up.first] = up.second;
  }
  return ret;
}
int buffer[10000];
void solve() {
  int n;
  cin >> n;
  vector<int> r(n);
  for (int i = 0; i < int(n); ++i) cin >> r[i];
  vector<int> a = r;
  sort((a).begin(), (a).end());
  a.erase(unique((a).begin(), (a).end()), a.end());
  for (int i = 0; i < int((r).size()); ++i)
    r[i] = distance(a.begin(), lower_bound((a).begin(), (a).end(), r[i]));
  vector<vector<int> > g(n);
  for (int i = 0; i < int(n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  int ans = 0;
  for (int i = 0; i < int(n); ++i) {
    buffer[0] = r[i];
    ans = max(ans, dfs(i, -1, r, g, buffer, 1));
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
