#include <bits/stdc++.h>
using namespace std;
class Person {
 public:
  Person();
  Person(string first, string last);
  virtual ~Person();
  string first;
  string last;
};
Person::Person() : first(""), last("") {}
Person::Person(string first, string last) : first(first), last(last) {}
Person::~Person() {}
int main(int argc, char **argv) {
  uint64_t n = 0;
  string line = "";
  if (getline(cin, line)) {
    stringstream ss(line);
    ss >> n;
  }
  vector<Person> ppVector;
  uint64_t lineIdx = 0;
  while (getline(cin, line)) {
    stringstream ss(line);
    Person person;
    ss >> person.first >> person.last;
    ppVector.push_back(person);
    ++lineIdx;
    if (lineIdx == n) break;
  }
  uint64_t indexArr[n];
  uint64_t indexArrIdx = 0;
  if (getline(cin, line)) {
    stringstream ss(line);
    while (indexArrIdx < n) {
      ss >> indexArr[indexArrIdx++];
      --indexArr[indexArrIdx - 1];
    }
  }
  vector<string> trueHandles;
  string smallestName = "";
  for (uint64_t i = 0; i != n; ++i) {
    string first = ppVector[indexArr[i]].first;
    string last = ppVector[indexArr[i]].last;
    if (i > 0) {
      int64_t compareResult = first.compare(last);
      compareResult /= abs(compareResult);
      switch (compareResult) {
        case -1: {
          int64_t compareFirstPrev = first.compare(trueHandles[i - 1]);
          compareFirstPrev /= abs(compareFirstPrev);
          if (compareFirstPrev == 1) {
            trueHandles.push_back(first);
          } else {
            int64_t compareLastPrev = last.compare(trueHandles[i - 1]);
            compareLastPrev /= abs(compareLastPrev);
            if (compareLastPrev == 1) {
              trueHandles.push_back(last);
            } else {
              cout << "NO";
              return 0;
            }
          }
          break;
        }
        case 1: {
          int64_t compareLastPrev = last.compare(trueHandles[i - 1]);
          compareLastPrev /= abs(compareLastPrev);
          if (compareLastPrev == 1) {
            trueHandles.push_back(last);
          } else {
            int64_t compareFirstPrev = first.compare(trueHandles[i - 1]);
            compareFirstPrev /= abs(compareFirstPrev);
            if (compareFirstPrev == 1) {
              trueHandles.push_back(first);
            } else {
              cout << "NO";
              return 0;
            }
          }
          break;
        }
        case 0: {
          break;
        }
        default: {
          break;
        }
      }
    } else {
      int64_t compareResult = first.compare(last);
      compareResult /= abs(compareResult);
      switch (compareResult) {
        case -1: {
          trueHandles.push_back(first);
          break;
        }
        case 1: {
          trueHandles.push_back(last);
          break;
        }
        case 0: {
          break;
        }
        default: {
          break;
        }
      }
    }
  }
  cout << "YES";
  return 0;
}
