#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > vec;
int arr[100005];
vector<string> test;
int main() {
  int n, i;
  string a, b;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    if (a > b)
      vec.push_back(make_pair(b, a));
    else
      vec.push_back(make_pair(a, b));
  }
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] -= 1;
  }
  int ans = 1;
  for (i = 0; i < n; i++) {
    if (i == 0) {
      test.push_back(vec[arr[i]].first);
    } else if (i != 0) {
      if (vec[arr[i]].first > test[i - 1])
        test.push_back(vec[arr[i]].first);
      else if (vec[arr[i]].second > test[i - 1])
        test.push_back(vec[arr[i]].second);
      else {
        ans = 0;
        break;
      }
    }
  }
  if (ans == 1)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
