#include <bits/stdc++.h>
using namespace std;
const long long INF = 9223372036854775807;
const long long MOD = 1000000007;
const long double PI = acos(-1);
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void solve() {
  long long n;
  cin >> n;
  std::vector<string> arr1, arr2;
  for (long long i = 0; i < n; i++) {
    string s, s1;
    cin >> s >> s1;
    arr1.push_back(s);
    arr2.push_back(s1);
  }
  vector<long long> permu;
  for (long long i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    permu.push_back(temp);
  };
  string min;
  if (arr1[permu[0] - 1] > arr2[permu[0] - 1]) {
    min = arr2[permu[0] - 1];
  } else {
    min = arr1[permu[0] - 1];
  };
  long long done = 1;
  long long i = 1;
  string tempmin;
  string tempmax;
  while (done < n) {
    string s3 = arr1[permu[i] - 1];
    string s4 = arr2[permu[i] - 1];
    if (s3 > s4) {
      tempmin = s4;
      tempmax = s3;
    } else {
      tempmin = s3;
      tempmax = s4;
    };
    if (tempmin > min) {
      min = tempmin;
      i++;
      done++;
    } else if (tempmax > min) {
      min = tempmax;
      i++;
      done++;
      ;
    } else {
      break;
    }
  };
  if (done == n) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int test;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
