#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
  return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long INF64 = 1e18;
const long long INF32 = 1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  {
    long long n;
    cin >> n;
    pair<string, string> a[n + 1];
    for (long long i = (1); i <= (n); i++) {
      cin >> a[i].first >> a[i].second;
      if (a[i].first > a[i].second) swap(a[i].first, a[i].second);
    }
    long long b[n + 1];
    for (long long i = (1); i <= (n); i++) cin >> b[i];
    long long i = b[1];
    string ans = "YES", prev = a[i].first;
    for (long long j = (2); j <= (n); j++) {
      i = b[j];
      if (prev > a[i].second) {
        ans = "NO";
        break;
      }
      prev = (prev < a[i].first ? a[i].first : a[i].second);
    }
    cout << ans << endl;
  }
  return 0;
}
