#include <bits/stdc++.h>
using namespace std;
void input(int arr[], int size) {
  for (int i = 0; i < size; i++) {
    cin >> arr[i];
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int list1[n], list2[m];
  input(list1, n);
  input(list2, m);
  sort(list1, list1 + n);
  sort(list2, list2 + m);
  if (list1[0] == list2[0]) {
    cout << list1[0] << endl;
  } else {
    int a = list1[0], b = list2[0];
    if (a < b) {
      cout << a * 10 + b << endl;
    } else {
      cout << b * 10 + a << endl;
    }
  }
}
