#include <bits/stdc++.h>
using namespace std;
pair<string, string> s[100005], S[100005];
char t1[55], t2[55];
int main() {
  int n, i;
  while (~scanf("%d", &n)) {
    for (i = 1; i <= n; i++) {
      scanf("%s%s", t1, t2);
      s[i] = pair<string, string>(t1, t2);
    }
    for (i = 1; i <= n; i++) {
      int tmp;
      scanf("%d", &tmp);
      S[i] = s[tmp];
    }
    string cur;
    for (i = 1; i <= n; i++) {
      if (i == 1)
        cur = min(S[i].first, S[i].second);
      else if (S[i].first < cur && S[i].second < cur)
        break;
      else if (S[i].first > cur && S[i].second > cur)
        cur = min(S[i].first, S[i].second);
      else if (S[i].first > cur)
        cur = S[i].first;
      else
        cur = S[i].second;
    }
    printf("%s\n", i <= n ? "NO" : "YES");
  }
  return 0;
}
