#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  pair<string, string> arr[n];
  vector<int> ord(n);
  string a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    arr[i] = make_pair(a, b);
  }
  for (int i = 0; i < n; i++) {
    cin >> ord[i];
    ord[i]--;
  }
  string handle[n];
  handle[ord[0]] = min(arr[ord[0]].first, arr[ord[0]].second);
  for (int i = 1; i < n; i++) {
    string prev = handle[ord[i - 1]];
    pair<string, string> nex = arr[ord[i]];
    if (min(nex.first, nex.second) > prev) {
      handle[ord[i]] = min(nex.first, nex.second);
    } else if (max(nex.first, nex.second) > prev) {
      handle[ord[i]] = max(nex.first, nex.second);
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}
