#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
void seriy() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
vector<string> s[2];
vector<int> in;
int n;
bool flag = 0;
void rec(int i) {
  if (i == n - 1) {
    flag = 1;
    return;
  }
  string first = s[0][in[i]];
  string a = s[0][in[i + 1]];
  string b = s[1][in[i + 1]];
  bool g = 0;
  if (a >= first)
    rec(i + 1);
  else if (b >= first) {
    swap(s[0][in[i + 1]], s[1][in[i + 1]]);
    rec(i + 1);
  }
}
int main() {
  seriy();
  cin >> n;
  s[0].resize(n);
  s[1].resize(n);
  in.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> s[0][i] >> s[1][i];
    if (s[0][i] > s[1][i]) {
      swap(s[0][i], s[1][i]);
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> in[i];
    in[i]--;
  }
  rec(0);
  cout << ((flag) ? "YES" : "NO");
  return 0;
}
