#include <bits/stdc++.h>
using namespace std;
void print(vector<int> vec) {
  for (int i = 1; i < vec.size(); i++) {
    cout << vec[i];
  }
}
int main() {
  int n, m;
  int count2 = 0;
  bool istrue = true;
  cin >> n >> m;
  vector<int> nvec;
  vector<int> mvec(n + 1, 0);
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    nvec.push_back(temp);
    cin >> temp;
    ans.push_back(temp);
  }
  for (int i = 0; i < nvec.size(); i++) {
    for (int j = 0; j < nvec.size(); j++) {
      if (i != j) {
        if (nvec[i] == nvec[j] && ans[i] != ans[j]) {
          istrue = false;
        }
      }
    }
  }
  if (nvec.size() < n) istrue = false;
  for (int i = 0; i < nvec.size(); i++) {
    int temp;
    cin >> temp;
    mvec[nvec[i]] = ans[i];
  }
  for (int i = 1; i < mvec.size(); i++) {
    if (mvec[i] == 0) count2++;
  }
  if (count2 > n) istrue = false;
  if (istrue)
    print(mvec);
  else
    cout << -1 << endl;
  return 0;
}
