#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed;
  cout << setprecision(12);
  long long n1, n2;
  cin >> n1 >> n2;
  long long a[n1], b[n2], cnt1[10] = {0}, cnt2[10] = {0};
  for (long long i = 0; i < n1; i++) {
    cin >> a[i];
    cnt1[a[i]]++;
  }
  for (long long i = 0; i < n2; i++) {
    cin >> b[i];
    cnt2[b[i]]++;
  }
  for (long long i = 0; i < 10; i++)
    if (cnt1[i] != 0 && cnt2[i] != 0) {
      cout << i;
      return 0;
    }
  sort(a, a + n1);
  sort(b, b + n2);
  cout << min(a[0] * 10 + b[0], b[0] * 10 + a[0]);
  return 0;
}
void setprime(bool isprime[], long long n) {
  for (long long i = 0; i < n; i++) isprime[i] = true;
  isprime[0] = false;
  isprime[1] = false;
  for (long long i = 2; i < n; i++) {
    for (long long j = 2; i * j < n; j++) isprime[i * j] = false;
  }
}
long long BinarySearch(long long arr[], long long first, long long last,
                       long long search) {
  long long middle = (first + last) / 2;
  while (first <= last) {
    if (arr[middle] < search) {
      first = middle + 1;
    } else if (arr[middle] == search) {
      return middle;
    } else {
      last = middle - 1;
    }
    middle = (first + last) / 2;
  }
  if (first > last) {
    return -1;
  }
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
void showArray(long long a[], long long n) {
  for (long long i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
