#include <bits/stdc++.h>
using namespace std;
int main() {
  char ch = false;
  int n, m, i, s = 0, small = 9, min = 9, *size, arr[9] = {9};
  cin >> n >> m;
  size = new int[m + n];
  for (i = 0; i < (m + n); i++) {
    cin >> size[i];
  }
  for (i = 0; i < n; i++) {
    for (int j = n; j < (m + n); j++) {
      if (size[i] == size[j]) {
        ch = true;
        arr[s] = size[i];
        s++;
      }
    }
  }
  if (ch == true) {
    for (i = 0; i < s; i++) {
      if (min > arr[i]) min = arr[i];
    }
    cout << min << endl;
  } else {
    for (i = 0; i < n; i++) {
      if (min > size[i]) min = size[i];
    }
    for (i = n; i < (m + n); i++) {
      if (small > size[i]) small = size[i];
    }
    if (small < min)
      cout << small << min << endl;
    else
      cout << min << small << endl;
  }
  return 0;
}
