#include <bits/stdc++.h>
using namespace std;
bool larger(string a, string b) {
  int s = min(a.length(), b.length());
  for (int i = 0; i < s; i++)
    if (a[i] != b[i]) return (a[i] < b[i]);
  return (a.length() < b.length());
}
int main() {
  int n;
  cin >> n;
  vector<string> ft(n), lt(n);
  for (int i = 0; i < n; i++) cin >> ft.at(i) >> lt.at(i);
  vector<int> order(n);
  for (int i = 0; i < n; i++) {
    cin >> order.at(i);
    order.at(i)--;
  }
  int choose = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (choose == 0) {
      bool found = false;
      if (larger(ft.at(order.at(i)), ft.at(order.at(i + 1))) ||
          larger(ft.at(order.at(i)), lt.at(order.at(i + 1)))) {
        found = true;
        choose = 1;
      }
      if (larger(lt.at(order.at(i)), ft.at(order.at(i + 1))) ||
          larger(lt.at(order.at(i)), lt.at(order.at(i + 1)))) {
        if (choose == 1)
          choose = 0;
        else
          choose = 2;
        found = true;
      }
      if (!found) return cout << "NO", 0;
    } else if (choose == 1) {
      bool found = false;
      choose = 0;
      if (larger(ft.at(order.at(i)), ft.at(order.at(i + 1)))) {
        found = true;
        choose = 1;
      }
      if (larger(lt.at(order.at(i)), ft.at(order.at(i + 1)))) {
        found = true;
        if (choose == 1)
          choose = 0;
        else
          choose = 2;
      }
      if (!found) return cout << "NO", 0;
    } else {
      bool found = false;
      choose = 0;
      if (larger(ft.at(order.at(i)), lt.at(order.at(i + 1)))) {
        found = true;
        choose = 1;
      }
      if (larger(lt.at(order.at(i)), lt.at(order.at(i + 1)))) {
        found = true;
        if (choose == 1)
          choose = 0;
        else
          choose = 2;
      }
      if (!found) return cout << "NO", 0;
    }
  }
  cout << "YES";
}
