#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  vector<string> s1, s2;
  cin >> n;
  bool ans = true;
  for (long long i = 0; i < n; i++) {
    string t1, t2;
    cin >> t1 >> t2;
    s1.push_back(t1);
    s2.push_back(t2);
  }
  int p[100010];
  for (long long i = 0; i < n; i++) cin >> p[i], p[i]--;
  string last = min(s1[p[0]], s2[p[0]]);
  for (long long i = 1; i <= n - 1; i++) {
    if (last > s1[p[i]] && last > s2[p[i]])
      ans = false;
    else {
      if (last < s1[p[i]] && last < s2[p[i]])
        last = min(s1[p[i]], s2[p[i]]);
      else if (last < s1[p[i]])
        last = s1[p[i]];
      else
        last = s2[p[i]];
    }
  }
  if (ans) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
  return 0;
}
