#include <bits/stdc++.h>
using namespace std;
int n;
string s[100009][4], q, e;
int a[100009], sz1, sz2, l;
int check(string x, string y) {
  l = 0;
  sz1 = x.size();
  sz2 = y.size();
  for (int i = 0; i < sz1; i++) {
    if (x[i] < y[i]) {
      l = 1;
      break;
    }
    if (x[i] > y[i]) {
      l = 2;
      break;
    }
  }
  if (l == 0) {
    if (sz1 <= sz2)
      l = 1;
    else
      l = 2;
  }
  return l;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i][1] >> s[i][2];
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (check(s[a[1]][1], s[a[1]][2]) == 1)
    q = s[a[1]][1];
  else
    q = s[a[1]][2];
  for (int i = 2; i <= n; i++) {
    if (check(s[a[i]][1], s[a[i]][2]) == 1)
      e = s[a[i]][1];
    else
      e = s[a[i]][2];
    if (check(q, e) == 2) {
      if (e == s[a[i]][2])
        e = s[a[i]][1];
      else
        e = s[a[i]][2];
      if (check(q, e) == 2) {
        cout << "NO" << endl;
        return 0;
      } else
        q = e;
    } else
      q = e;
  }
  cout << "YES" << endl;
  return 0;
}
