#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << '\n';
  err(++it, args...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string lts(long long int x) {
  stringstream second;
  second << x;
  return second.str();
}
long long int stl(string x) {
  stringstream second(x);
  long long int temp;
  second >> temp;
  return temp;
}
string cts(char x) {
  string second(1, x);
  return second;
}
const int MOD = 1e9 + 7;
const int MAXN = 100005;
template <typename T>
void maxself(T& a, T b) {
  a = max(a, b);
}
template <typename T>
void minself(T& a, T b) {
  a = min(a, b);
}
pair<string, string> A[MAXN];
pair<string, string> tmp[MAXN];
string str[MAXN];
int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (long long int i = (0); i <= (long long int)(n - 1); ++i) {
    cin >> tmp[i].first >> tmp[i].second;
  }
  for (long long int i = (0); i <= (long long int)(n - 1); ++i) {
    int x;
    cin >> x;
    A[i] = tmp[x - 1];
  }
  str[0] = min(A[0].first, A[0].second);
  bool yes = 1;
  for (long long int i = (1); i <= (long long int)(n - 1); ++i) {
    string pre = str[i - 1];
    string fi = A[i].first, se = A[i].second;
    if (fi > se) swap(fi, se);
    if (fi > pre)
      str[i] = fi;
    else if (se > pre)
      str[i] = se;
    if (fi < pre && se < pre) {
      cout << "NO\n";
      return 0;
    }
  }
  if (yes)
    cout << "YES\n";
  else
    cout << "NO\n";
}
