#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  for (int &st : s) {
    cin >> st;
  }
  vector<int> c(M);
  for (int &ct : c) {
    cin >> ct;
  }
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    string numstr;
    numstr = to_string(i);
    for (int j = 0; j < M; j++) {
      if (numstr[s[j] - 1] == c[j]) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}
