#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, arr1[10] = {}, arr2[10] = {};
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> arr1[i];
  for (int i = 0; i < m; i++) cin >> arr2[i];
  sort(arr1, arr1 + n);
  sort(arr2, arr2 + m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr1[i] == arr2[j]) {
        cout << arr1[i];
        return 0;
      }
    }
  }
  if (n == 1 && m != 1) {
    cout << arr1[0];
    return 0;
  }
  if (m == 1 && n != 1) {
    cout << arr2[0];
    return 0;
  }
  if (arr1[0] == arr2[0]) {
    cout << arr1[0];
    return 0;
  } else {
    if (arr1[0] < arr2[0]) {
      cout << arr1[0] << arr2[0];
      return 0;
    }
    if (arr2[0] < arr1[0]) {
      cout << arr2[0] << arr1[0];
      return 0;
    }
  }
  return 0;
}
