#include <bits/stdc++.h>
using namespace std;
unsigned short int minimum(unsigned short int a[]) {
  unsigned short int mi = a[0];
  for (int i = 1; a[i] != 0; i++)
    if ((mi > a[i]) && (a[i] <= 9)) mi = a[i];
  return mi;
}
unsigned short int n, k;
unsigned short int a[9], b[9];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < k; i++) cin >> b[i];
  unsigned short int num1 = minimum(a), num2 = minimum(b);
  if (num1 > num2)
    cout << num2 << num1;
  else if (num1 < num2)
    cout << num1 << num2;
  else if (num1 == num2)
    cout << num1;
  return 0;
}
