#include <bits/stdc++.h>
using namespace std;
int n, p[100005];
string a[100005], b[100005], h[100005], ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > b[i]) {
      swap(a[i], b[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  ans = "YES";
  for (int i = 1; i <= n; i++) {
    if (a[p[i]] > h[i - 1]) {
      h[i] = a[p[i]];
    } else if (b[p[i]] > h[i - 1]) {
      h[i] = b[p[i]];
    } else {
      ans = "NO";
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
