#include <bits/stdc++.h>
using namespace std;
const long int z = 1000000007;
long long int h[1000009];
int main() {
  vector<pair<string, string> > p;
  long long int n, m, i, x = 0, y, v, j, d, c, k = 0, max = 0, sum = 0,
                         flag = 0;
  cin >> n;
  string s, t;
  long long int a[n], b[n];
  for (i = 0; i < n; i++) {
    cin >> s >> t;
    if (s < t) {
      p.push_back(make_pair(s, t));
    } else
      p.push_back(make_pair(t, s));
  }
  cin >> x;
  s = p[x - 1].first;
  for (i = 1; i < n; i++) {
    cin >> x;
    if (s < p[x - 1].first)
      s = p[x - 1].first;
    else if (s < p[x - 1].second)
      s = p[x - 1].second;
    else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
