#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, x = 20, c = 0;
  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];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        c++;
        x = min(x, a[i]);
      }
    }
  }
  if (c == 0) {
    sort(a, a + n);
    sort(b, b + m);
    if (a[0] > b[0])
      cout << b[0] * 10 + a[0];
    else
      cout << a[0] * 10 + b[0];
  } else
    cout << x;
  return 0;
}
