#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
  long long ret = 1;
  long long b = a;
  while (n) {
    if (n & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    n >>= 1;
  }
  return (long long)ret;
}
using namespace std;
vector<pair<string, string> > v;
vector<int> ans;
int main() {
  int i, j;
  int n;
  cin >> n;
  for (j = 0; j < n; j++) {
    string s1, s2;
    cin >> s1 >> s2;
    v.push_back(make_pair(s1, s2));
  }
  for (j = 0; j < n; j++) {
    int x;
    cin >> x;
    x--;
    ans.push_back(x);
  }
  string prev;
  if (v[ans[0]].first < v[ans[0]].second)
    prev = v[ans[0]].first;
  else
    prev = v[ans[0]].second;
  for (j = 1; j < n; j++) {
    string str1 = v[ans[j]].first, str2 = v[ans[j]].second;
    string m1, m2;
    int ok = 0, ok1 = 0;
    if (str1 > str2) {
      m1 = str1;
      m2 = str2;
    } else {
      m1 = str2;
      m2 = str1;
    }
    if (m2 >= prev) ok = 1;
    if (m1 >= prev) ok1 = 1;
    if (ok && ok1) {
      prev = m2;
    } else if (!ok && ok1) {
      prev = m1;
    } else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
