#include <bits/stdc++.h>
using namespace std;
template <typename t1, typename t2>
ostream& operator<<(ostream& os, const pair<t1, t2>& a) {
  os << a.first << ' ' << a.second;
  return os;
}
template <typename typ>
void vout(vector<typ>& v) {
  for (int vint = 0; vint < (int)(v).size(); vint++) {
    cout << (v)[vint];
    if (vint == (int)(v).size() - 1)
      cout << '\n';
    else
      cout << ' ';
  }
}
template <typename typ>
void arrout(typ* arr, int l) {
  for (int i = 0; i < l; i++) {
    cout << arr[i];
    if (i < l - 1)
      cout << ' ';
    else
      cout << '\n';
  }
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int main() {
  int n;
  cin >> n;
  string s[2 * n];
  for (int i = 0; i < 2 * n; i++) {
    cin >> s[i];
  }
  int p;
  cin >> p;
  p--;
  string last = min(s[2 * p], s[2 * p + 1]);
  for (int i = 1; i < n; i++) {
    cin >> p;
    p--;
    if (s[2 * p] > s[2 * p + 1]) {
      swap(s[2 * p], s[2 * p + 1]);
    }
    if (s[2 * p] > last) {
      last = s[2 * p];
    } else if (s[2 * p + 1] > last) {
      last = s[2 * p + 1];
    } else {
      cout << ("NO") << '\n';
      return 0;
    }
  }
  cout << ("YES") << '\n';
}
