#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n], ar[m];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < m; i++) cin >> ar[i];
  sort(arr, arr + n);
  sort(ar, ar + m);
  int sum = 0;
  int mi = 999999999;
  int arrr[2];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      sum = (arr[i] * 10) + ar[j];
      if (mi > sum) {
        mi = sum;
        arrr[0] = arr[i];
        arrr[1] = ar[j];
      }
    }
  }
  if (arrr[0] == arrr[1]) {
    cout << arrr[0];
  } else {
    cout << arrr[0] << arrr[1];
  }
  return 0;
}
