#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i];
  }
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << "-1" << endl;
      break;
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << "-1" << endl;
        break;
      }
    }
  }
  vector<int> a(N);
  for (int i = 0; i < M; i++) {
    a[s[i] - 1] = c[i];
  }
  for (int i = 0; i < M; i++) {
    cout << a[i];
  }
}
