#include <bits/stdc++.h>
using namespace std;
long long n, i, d[100005];
string a[2][100005], b, c, e;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[0][i] >> a[1][i];
  }
  cin >> d[1];
  if (a[0][d[1]] < a[1][d[1]])
    b = a[0][d[1]];
  else
    b = a[1][d[1]];
  for (i = 2; i <= n; i++) {
    cin >> d[i];
    if (a[0][d[i]] < a[1][d[i]]) {
      c = a[0][d[i]];
      e = a[1][d[i]];
    } else {
      e = a[0][d[i]];
      c = a[1][d[i]];
    }
    if (b < c) {
      b = c;
    } else if (b < e) {
      b = e;
    } else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
