#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
inline int gcd(int a, int b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? ((a - b) ? gcd(a % b, b) : a) : a;
}
void solve() {
  int n, x;
  string s1, s2, t;
  cin >> n;
  vector<pair<string, string> > v;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    if (s1 > s2)
      v.push_back(make_pair(s2, s1));
    else
      v.push_back(make_pair(s1, s2));
  }
  for (int i = 0; i < n; i++) cin >> a[i];
  t = "";
  for (int i = 0; i < n; i++) {
    s1 = v[a[i] - 1].first;
    s2 = v[a[i] - 1].second;
    if (s1 >= t)
      t = s1;
    else if (s2 >= t)
      t = s2;
    else {
      cout << "NO";
      return;
    }
  }
  cout << "YES";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
