#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  int arr[x];
  int arr2[y];
  for (int i = 0; i < x; i++) {
    cin >> arr[i];
  }
  for (int j = 0; j < y; j++) {
    cin >> arr2[j];
  }
  sort(arr, arr + x);
  sort(arr2, arr2 + y);
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      if (arr[i] == arr2[j]) {
        cout << arr[i] << endl;
        return 0;
      }
    }
  }
  int koko1 = arr[0];
  int koko2 = arr2[0];
  int smallest;
  if (koko1 < koko2)
    cout << koko1 << koko2 << endl;
  else
    cout << koko2 << koko1 << endl;
  return 0;
}
