#include <bits/stdc++.h>
using namespace std;
const int SS = 5e2 + 123;
const int N = 1e5 + 123;
const int NN = 1e6 + 123;
const int M = 1e7 + 123;
const int MM = 1e8 + 123;
const int inf = 1e9 + 123;
const long long INF = 1e18 + 123;
const long long MAXN = 1e10 + 123;
const long long MOD = 1e9 + 7;
const long long mod = 555557;
const double pi = acos(-1.0);
string s[N], t[N], cur;
int n, a[N], name = 1, surname = 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> s[i] >> t[i];
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cur = min(t[a[1]], s[a[1]]);
  for (int i = 2; i <= n; ++i) {
    if (min(s[a[i]], t[a[i]]) < cur && max(s[a[i]], t[a[i]]) < cur)
      cout << "NO", exit(0);
    else if (min(s[a[i]], t[a[i]]) > cur)
      cur = min(s[a[i]], t[a[i]]);
    else if (max(s[a[i]], t[a[i]]) > cur)
      cur = max(s[a[i]], t[a[i]]);
  }
  cout << "YES";
}
