#include <bits/stdc++.h>
using namespace std;
long long mx = -1e9, mn = 1e9 + 5;
long long T, n, m, k, ans, t, a[100005], b[1000005], c[1000], d, l, r, sum, mid,
    coin, cnt, pos, number, x, y, z, h;
vector<long long> v, v1;
map<long long, long long> mp;
map<long long, long long>::iterator it;
map<long long, long long> mm;
pair<long long, long long> p[200005];
queue<pair<long long, long long> > q, q1;
priority_queue<long long> pq;
bool prime[105];
string s[100005], s1[100005];
int main() {
  cin >> n;
  string second;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> s1[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (i == 1) {
      second = min(s[x], s1[x]);
      continue;
    }
    if (second < s[x] && second < s1[x]) {
      second = min(s[x], s1[x]);
      continue;
    }
    if (second < s[x]) {
      second = s[x];
      continue;
    }
    if (second < s1[x]) {
      second = s1[x];
      continue;
    }
    cout << "NO";
    return 0;
  }
  cout << "YES";
}
