#include <bits/stdc++.h>
using namespace std;
int i, j;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  sort(a, a + n);
  sort(b, b + m);
  if (a[0] == b[0]) {
    cout << a[0] << endl;
  } else {
    int min = 99999, current = 999999;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (a[i] == b[j]) {
          current = b[j];
        }
      }
      if (min > current) {
        min = current;
      }
    }
    if (min != 99999) {
      cout << min << endl;
    } else {
      int num1 = a[0] * 10 + b[0];
      int num2 = b[0] * 10 + a[0];
      if (num1 < num2) {
        cout << a[0] << b[0] << endl;
      } else {
        cout << b[0] << a[0] << endl;
      }
    }
  }
}
