#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, t;
  cin >> n >> t;
  long long arr1[n + 1], arr2[t + 1];
  for (long long i = 0; i < n; i++) {
    cin >> arr1[i];
  }
  sort(arr1, arr1 + n);
  for (long long i = 0; i < t; i++) {
    cin >> arr2[i];
  }
  sort(arr2, arr2 + n);
  long long x = 0, num[1000];
  for (long long i = 0; i < t; i++) {
    if (arr1[0] == arr2[i]) {
      cout << arr1[0] << endl;
      return 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (arr2[0] == arr1[i]) {
      cout << arr2[0] << endl;
      return 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < t; j++) {
      num[x++] = arr1[i] * 10 + arr2[j];
      num[x++] = arr1[i] + arr2[j] * 10;
    }
  }
  sort(num, num + x);
  cout << num[0] << endl;
}
