#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30), mod = 1000000007;
const int N = 100005;
int n, a[N], d[2][N], t[N + N];
string f, s;
pair<string, int> v[N + N];
void add(int R) {
  for (; R < n + n; R = (R | (R + 1))) t[R]++;
}
int sum(int R) {
  int res = 0;
  for (; R >= 0; R = (R & (R + 1)) - 1) res += t[R];
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> f >> s;
    v[2 * i] = make_pair(f, 2 * i);
    v[2 * i + 1] = make_pair(s, 2 * i + 1);
  }
  sort(v, v + n + n);
  for (int i = 0, x; i < n; i++) {
    cin >> x;
    x--;
    a[i] = x;
  }
  for (int i = 0; i < n + n; i++) d[v[i].second % 2][v[i].second / 2] = i;
  for (int j = n - 1; j >= 0; j--) {
    int i = a[j], p1 = d[0][i], p2 = d[1][i];
    if (p1 < p2) swap(p1, p2);
    if (sum(p1) == 0)
      add(p1);
    else {
      if (sum(p2) == 0)
        add(p2);
      else {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
  return 0;
}
