#include <bits/stdc++.h>
using namespace std;
int arr[100009];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  vector<pair<string, string> > v;
  int n, i, flag = 0;
  string a, b, x;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  string last = "";
  for (i = 0; i < n; i++) {
    if (i == 0) {
      x = min(v[arr[i] - 1].first, v[arr[i] - 1].second);
      last = x;
    } else {
      a = v[arr[i] - 1].first, b = v[arr[i] - 1].second;
      if (a > b) {
        if (b > last) {
          last = b;
        } else if (a > last) {
          last = a;
        } else {
          flag = 1;
          break;
        }
      } else {
        if (a > last) {
          last = a;
        } else if (b > last) {
          last = b;
        } else {
          flag = 1;
          break;
        }
      }
    }
  }
  if (flag == 1)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
