#include <bits/stdc++.h>
using namespace std;
long long a[1000001], b[1000001];
map<long long, long long> m1, m2;
int main() {
  long long n, i, j, m;
  cin >> n >> m;
  for (i = 0; i < n; ++i) {
    cin >> a[i];
    m1[a[i]] = 1;
  }
  for (j = 0; j < m; ++j) {
    cin >> b[j];
    m2[b[j]] = 1;
  }
  sort(a, a + n);
  sort(b, b + m);
  for (i = 1; i <= 9; ++i) {
    if (m1[i] == 1 && m2[i] == 1) {
      cout << i;
      exit(0);
    }
  }
  cout << ((10 * min(a[0], b[0])) + max(a[0], b[0]));
}
