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