#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N |= (1LL << pos); }
int Reset(int N, int pos) { return N &= ~(1LL << pos); }
bool Check(int N, int pos) { return N & (1LL << pos); }
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
template <class T>
void cmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void cmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
int len(const T &c) {
  return (int)c.size();
}
template <class T>
int len(char c[]) {
  return (int)strlen(c);
}
string itos(long n) {
  string s;
  while (n) {
    s += (n % 10 + 48);
    n /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
long stoi(string s) {
  long n = 0;
  for (int i(0), _n(len(s)); i < _n; ++i) n = n * 10 + (s[i] - 48);
  return n;
}
struct node {
  string f, s;
};
int main() {
  ios_base::sync_with_stdio(false);
  long n, a;
  node ar[100005];
  cin >> n;
  for (int i(0), _n(n); i < _n; ++i) {
    cin >> ar[i].f >> ar[i].s;
    if (ar[i].f > ar[i].s) swap(ar[i].f, ar[i].s);
  }
  string pre = "";
  int f = 0;
  for (int i(0), _n(n); i < _n; ++i) {
    cin >> a;
    a--;
    if (ar[a].f > pre)
      pre = ar[a].f;
    else if (ar[a].s > pre)
      pre = ar[a].s;
    else
      f = 1;
  }
  if (f)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
