#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, count1 = 0, count2 = 0;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  sort(a, a + n);
  sort(b, b + n);
  for (int i = 0; i < m; i++) {
    if (a[0] == b[i]) {
      count1++;
      break;
    } else {
      continue;
    }
  }
  for (int i = 0; i < n; i++) {
    if (b[0] == a[i]) {
      count2++;
      break;
    } else {
      continue;
    }
  }
  if (count1 == 1 || count2 == 1) {
    if (a[0] > b[0]) {
      cout << b[0] << endl;
    } else {
      cout << a[0] << endl;
    }
  } else {
    if (a[0] > b[0]) {
      cout << b[0] << a[0] << endl;
    } else {
      cout << a[0] << b[0] << endl;
    }
  }
  return 0;
}
