#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n), v1(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  for (int j = 0; j < n; ++j) {
    cin >> v1[j];
  }
  sort(v1.begin(), v1.end()), sort(v.begin(), v.end());
  if (v[0] == v1[0]) {
    cout << 0 << endl;
    return 0;
  }
  for (int k = 1;; ++k) {
    int f = 0, f1 = 0;
    for (int i = 0; i < to_string(k).size(); ++i) {
      if (find(v.begin(), v.end(), to_string(k)[i] - '0') != v.end()) f++;
      if (find(v1.begin(), v1.end(), to_string(k)[i] - '0') != v1.end()) f++;
    }
    if (f + f1 >= 2) {
      cout << k << endl;
      return 0;
    }
  }
}
