#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<string, string> > vals;
  string s, temp, temp2, k;
  for (int i = 0; i < n; i++) {
    cin >> s >> k;
    vals.push_back(make_pair(s, k));
  }
  int a;
  bool ans = 1;
  string x = "a";
  for (int i = 0; i < n; i++) {
    cin >> a;
    temp = vals[a - 1].first;
    temp2 = vals[a - 1].second;
    if (min(temp, temp2) >= x)
      x = min(temp, temp2);
    else if (max(temp, temp2) >= x)
      x = max(temp, temp2);
    else
      ans = 0;
  }
  if (ans)
    return cout << "YES", 0;
  else
    return cout << "NO", 0;
}
