#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long M = (long long)1e9 + 7;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
void Char(char* ch) { scanf("%s", ch); }
template <typename t>
t abs(t a) {
  if (a >= 0) return a;
  return -a;
}
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " ";
  err(++it, args...);
}
vector<string> s;
unordered_map<string, int> mp;
int p[N];
int main() {
  int n = Int();
  for (int i = 1; i <= n; i++) {
    string a, b;
    cin >> a >> b;
    s.push_back(a);
    s.push_back(b);
    mp[a] = i;
    mp[b] = i;
  }
  sort(s.begin(), s.end());
  for (int i = 1; i <= n; i++) {
    p[i] = Int();
  }
  int j = 1;
  for (int i = 0; i < (int)s.size(); i++) {
    if (mp[s[i]] == p[j]) {
      j++;
      if (j == n + 1) break;
    }
  }
  if (j == n + 1) {
    return puts("YES"), 0;
  } else {
    return puts("NO"), 0;
  }
  return 0;
}
