#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
const int infi = 1e9;
const long long Linfi = (long long)9e18;
const long long MOD = 1000000007;
const int c1 = 11;
const int c2 = 37;
int n, k;
string s[100005], f[100005];
int p[100005];
void solve() {
  string a = "0";
  for (int i = 1; i <= n; i++) {
    int pos = p[i];
    if (f[pos] > a) {
      a = f[pos];
      continue;
    } else if (s[pos] > a) {
      a = s[pos];
      continue;
    }
    cout << "NO" << endl;
    return;
  }
  cout << "YES" << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  cin.ignore(1);
  for (int i = 1; i <= n; i++) {
    cin >> f[i] >> s[i];
    if (f[i] > s[i]) swap(f[i], s[i]);
  }
  for (int i = 1; i <= n; i++) cin >> p[i];
  solve();
  return 0;
}
