#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long oo = INT_MAX;
const long long MOD = 1e9 + 7;
const long long sz = 1e5 + 5;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long tc = 1;
  while (tc--) {
    long long n;
    cin >> n;
    vector<pair<string, string>> names(n);
    for (auto& el : names) {
      cin >> el.first >> el.second;
      if (el.first > el.second) swap(el.first, el.second);
    }
    vector<long long> perm(n);
    for (auto& el : perm) {
      cin >> el;
      el--;
    }
    string prev;
    if (names[perm.front()].first < names[perm.front()].second)
      prev = names[perm.front()].first;
    else
      prev = names[perm.front()].second;
    for (long long i = 1; i < n; ++i) {
      if (prev > names[perm[i]].first && prev > names[perm[i]].second)
        return 0 * printf("NO\n");
      if (prev < names[perm[i]].first)
        prev = names[perm[i]].first;
      else if (names[perm[i]].first < prev && prev <= names[perm[i]].second)
        prev = names[perm[i]].second;
    }
    cout << "YES"
         << "\n";
  }
}
