#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  for (int i = (0); i < (m); i++) cin >> s[i];
  vector<char> c(m);
  for (int i = (0); i < (m); i++) cin >> c[i];
  int left, right;
  if (n == 1) {
    left = 0;
    right = 10;
  }
  if (n == 2) {
    left = 10;
    right = 100;
  }
  if (n == 3) {
    left = 100;
    right = 1000;
  }
  for (int i = (left); i < (right); i++) {
    int ans = 0;
    string str = to_string(i);
    for (int j = (0); j < (m); j++) {
      if (str[s[j] - 1] == c[j]) ans++;
    }
    if (ans == m) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
}
