#include <bits/stdc++.h>
using namespace std;
long long n, p[100005];
struct node {
  string s1, s2;
};
node v[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> v[i].s1 >> v[i].s2;
  }
  for (i = 1; i <= n; i++) {
    cin >> p[i];
  }
  string c = min(v[p[1]].s1, v[p[1]].s2);
  for (i = 2; i <= n; i++) {
    string a, b;
    a = min(v[p[i]].s1, v[p[i]].s2);
    b = max(v[p[i]].s1, v[p[i]].s2);
    if (c < a) {
      c = a;
      continue;
    }
    if (c < b) {
      c = b;
      continue;
    }
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  return 0;
}
