#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double pi = acos(-1.0);
const int INF = 1e9 + 7;
template <typename T>
inline vector<T> getvec(int n) {
  vector<T> tmp(n);
  for (int i = 0; i < (int)n; ++i) cin >> tmp[i];
  return tmp;
}
template <typename T>
inline void MustDie(T tmp) {
  cout << tmp;
  exit(0);
}
inline bool iscor(int k) {
  int d = 0;
  for (int i = 1; i <= (int)k; ++i) d += (k % i == 0);
  return (d > 2);
}
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  vector<pair<string, string> > s(n);
  for (int i = 0; i < (int)n; ++i) cin >> s[i].first >> s[i].second;
  std::vector<int> a = getvec<int>(n);
  string pr = min(s[a[0] - 1].first, s[a[0] - 1].second);
  for (int i = 1; i <= (int)n - 1; ++i) {
    if (max(s[a[i] - 1].first, s[a[i] - 1].second) < pr)
      MustDie("NO");
    else {
      min(s[a[i] - 1].first, s[a[i] - 1].second) > pr
          ? pr = min(s[a[i] - 1].first, s[a[i] - 1].second)
          : pr = max(s[a[i] - 1].first, s[a[i] - 1].second);
    }
  }
  cout << "YES";
  exit(0);
}
