#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LINF = numeric_limits<long long>::max();
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
vector<pair<string, string> > ns;
vector<pair<string, string> > a;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    ns.push_back(make_pair(s1, s2));
  }
  for (int i = 0; i < n; i++) {
    int j;
    cin >> j;
    j--;
    a.push_back(ns[j]);
  }
  if (a[0].second < a[0].first) swap(a[0].first, a[0].second);
  for (int i = 1; i < n; i++) {
    string mn = min(a[i].first, a[i].second);
    string mx = max(a[i].first, a[i].second);
    if (mn > a[i - 1].first) {
      a[i].first = mn;
    } else if (mx > a[i - 1].first) {
      a[i].first = mx;
    } else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
