#include <bits/stdc++.h>
using namespace std;
long long INF = 1E9;
long long M = 1E9 + 7;
inline long long power(long long a, long long p) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x);
    x = (x * x);
    p >>= 1;
  }
  return res;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (T x : p) os << x << " ";
  os << "]" << endl;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "{ ";
  for (T x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const map<Tk, Tv>& p) {
  os << "{ ";
  for (pair<Tk, Tv> x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) {
  os << "{" << p.first << ',' << p.second << "}";
  return os;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<string> f(n), l(n), prev(n);
  vector<int> p(n), h(n);
  for (long long i = 0; i < n; i++) {
    cin >> f[i] >> l[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
    h[p[i]] = i;
  }
  bool flag = true;
  for (long long i = 0; i < n; i++) {
    int pos = p[i];
    if (i == 0) {
      prev[i] = min(f[pos], l[pos]);
    } else {
      if (f[pos] > prev[i - 1] && l[pos] > prev[i - 1]) {
        prev[i] = min(f[pos], l[pos]);
      } else if (f[pos] > prev[i - 1]) {
        prev[i] = f[pos];
      } else if (l[pos] > prev[i - 1]) {
        prev[i] = l[pos];
      } else {
        flag = false;
        break;
      }
    }
  }
  if (flag)
    puts("YES");
  else
    puts("NO");
  return 0;
}
