#include <bits/stdc++.h>
using namespace std;
string s[100001][2];
string res[100001];
int comp(string a, string b) {
  int i = 0;
  while (i < a.size() && i < b.size()) {
    if (a[i] > b[i]) {
      return 1;
    } else if (a[i] < b[i]) {
      return -1;
    }
    i++;
  }
  if (a.size() > b.size())
    return 1;
  else
    return -1;
}
int main() {
  int n, x, i;
  cin >> n;
  int a[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> s[i][0] >> s[i][1];
  }
  for (i = 1; i <= n; i++) {
    cin >> x;
    a[i] = x;
  }
  int flag = 0;
  int p = comp(s[a[1]][0], s[a[1]][1]);
  if (p < 0)
    res[1] = s[a[1]][0];
  else
    res[1] = s[a[1]][1];
  for (i = 2; i <= n; i++) {
    int j = a[i];
    int k = comp(s[j][0], s[j][1]);
    string s1, s2;
    if (k < 0) {
      s1 = s[j][0];
      s2 = s[j][1];
    } else {
      s1 = s[j][1];
      s2 = s[j][0];
    }
    k = comp(s1, res[i - 1]);
    if (k < 0) {
      k = comp(s2, res[i - 1]);
      if (k < 0) {
        flag = -1;
        break;
      } else {
        res[i] = s2;
      }
    } else {
      res[i] = s1;
    }
  }
  if (flag == -1)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
