#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 6;
char a[N][55], b[N][55];
string z[N];
int main() {
  int n, m;
  bool ok = 1;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%s%s", &a[i], &b[i]);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    --x;
    string A = a[x];
    string B = b[x];
    string s1 = min(A, B);
    string s2 = max(A, B);
    z[i] = s1;
    if (i && z[i] < z[i - 1]) z[i] = s2;
    if (i && z[i] < z[i - 1]) ok = 0;
  }
  cout << (ok ? "YES" : "NO") << endl;
  return 0;
}
