#include <bits/stdc++.h>
using namespace std;
int find(int val, int arr[], int n) {
  for (int i = 0; i < n; i++) {
    if (arr[i] == val) return 1;
  }
  return 0;
}
int main() {
  int a, b, m1 = INT_MAX, m2 = INT_MAX, k, flag = 0;
  cin >> a >> b;
  int* arr1 = new int[a];
  int* arr2 = new int[b];
  int* ar = new int[10];
  for (int i = 0; i < 10; i++) ar[i] = 0;
  for (int i = 0; i < a; i++) {
    cin >> k;
    arr1[i] = k;
    ar[k] += 1;
    if (k < m1) m1 = k;
  }
  for (int i = 0; i < b; i++) {
    cin >> k;
    arr2[i] = k;
    ar[k] += 1;
    if (k < m2) m2 = k;
  }
  k = 1;
  while (k != 10) {
    if (ar[k] > 1) {
      cout << k << endl;
      flag = 1;
      break;
    }
    k++;
  }
  if (m1 <= m2 && flag == 0) {
    if (find(m1, arr2, b)) {
      cout << m1 << endl;
      flag = 1;
    } else if (find(m2, arr1, a)) {
      cout << m2 << endl;
      flag = 1;
    }
  }
  if (flag == 0) {
    if (m1 > m2) {
      int temp = m1;
      m1 = m2;
      m2 = temp;
    }
    cout << 10 * m1 + m2 << endl;
  }
  return 0;
}
