#include <bits/stdc++.h>
using namespace std;
FILE *file;
vector<vector<int> > P(101);
void fP(int n = 101) {
  P[0].push_back(1);
  P[1].push_back(1);
  P[1].push_back(1);
  for (int i = 2; i < 101; i++) {
    P[i].push_back(1);
    for (int j = 0; j < P[i - 1].size() - 1; j++) {
      P[i].push_back(P[i - 1][j] + P[i - 1][j + 1]);
    }
    P[i].push_back(1);
  }
}
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
vector<pair<string, string> > p;
int a[100000];
int main() {
  int n;
  cin >> n;
  string ch = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
  string s1, s2;
  cin >> s1 >> s2;
  p.push_back(make_pair("", ""));
  p.push_back(make_pair(s1, s2));
  for (int i = 1; i < n; i++) {
    cin >> s1 >> s2;
    p.push_back(make_pair(s1, s2));
  }
  bool mark = false;
  cin >> a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    if (p[a[i]].first < p[a[i]].second) {
      if (min(p[a[i - 1]].first, p[a[i - 1]].second) < p[a[i]].first) {
        p[a[i]].second = ch;
        continue;
      } else if (min(p[a[i - 1]].first, p[a[i - 1]].second) < p[a[i]].second) {
        p[a[i]].first = ch;
        continue;
      } else {
        mark = true;
      }
    } else {
      if (min(p[a[i - 1]].first, p[a[i - 1]].second) < p[a[i]].second) {
        p[a[i]].first = ch;
        continue;
      } else if (min(p[a[i - 1]].first, p[a[i - 1]].second) < p[a[i]].first) {
        p[a[i]].second = ch;
        continue;
      } else {
        mark = true;
      }
    }
  }
  if (mark) {
    cout << "NO";
  } else {
    cout << "YES";
  }
  return 0;
}
