#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long n, long long temp) {
  long long res = 1, y = a;
  while (n > 0) {
    if (n & 1) res = (res * y) % temp;
    y = (y * y) % temp;
    n /= 2;
  }
  return res % temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  string f[n + 1], l[n + 1], x;
  for (long long i = 1; i <= n; i++) cin >> f[i] >> l[i];
  long long a[n + 1];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  x = l[a[0]];
  if (f[a[0]].compare(l[a[0]]) <= 0) x = f[a[0]];
  bool flag = 0;
  for (long long i = 1; i < n; i++) {
    if (f[a[i]].compare(l[a[i]]) <= 0) {
      if (x.compare(f[a[i]]) < 0) {
        x = f[a[i]];
      } else if (x.compare(l[a[i]]) < 0) {
        x = l[a[i]];
      } else {
        flag = 1;
        break;
      }
    } else {
      if (x.compare(l[a[i]]) < 0) {
        x = l[a[i]];
      } else if (x.compare(f[a[i]]) < 0) {
        x = f[a[i]];
      } else {
        flag = 1;
        break;
      }
    }
  }
  if (flag)
    cout << "NO\n";
  else
    cout << "YES\n";
}
