#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n, arr[10] = {}, y = 9, z = 9;
  cin >> x >> n;
  for (int i = 0; i < x; i++) {
    int m;
    cin >> m;
    y = min(y, m);
    arr[m]++;
  }
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    z = min(z, m);
    arr[m]++;
  }
  for (int i = 1; i <= 9; i++) {
    if (arr[i] == 2) {
      cout << i << endl;
      return 0;
    }
  }
  cout << min(z, y) << max(z, y) << endl;
  return 0;
}
