#include <bits/stdc++.h>
using namespace std;
string names[100001][2];
int p[100001];
int n;
int dp[2][100001];
int helper(int flag, int i) {
  if (i == n) return 1;
  if (dp[flag][i] != -1) return dp[flag][i];
  if (names[p[i]][0] >= names[p[i - 1]][flag]) {
    if (helper(0, i + 1)) return dp[flag][i] = 1;
  }
  if (names[p[i]][1] >= names[p[i - 1]][flag]) {
    if (helper(1, i + 1)) return dp[flag][i] = 1;
  }
  return dp[flag][i] = 0;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> names[i][0] >> names[i][1];
  for (int i = 0; i < n; i++) cin >> p[i];
  memset(dp, -1, sizeof dp);
  if (helper(0, 1))
    cout << "YES" << endl;
  else {
    if (helper(1, 1))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
