#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[9], b[9], c[9];
  bool kek = false;
  int n, m, k, x, y;
  cin >> n >> m;
  if (n > m) {
    k = n;
  } else {
    k = m;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      if (a[i] == b[j] && a[i] >= 0 && b[j] >= 0) {
        c[i] = b[j];
      }
    }
  }
  int min = 10;
  for (int i = 0; i < 9; i++) {
    if (c[i] < min && c[i] >= 0) {
      min = c[i];
    }
  }
  if (min <= 9) {
    cout << min;
    kek = true;
  }
  min = 10;
  for (int i = 0; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
    }
  }
  x = min;
  min = 10;
  for (int i = 0; i < m; i++) {
    if (b[i] < min) {
      min = b[i];
    }
  }
  y = min;
  if (!kek) {
    if (x * 10 + y < y * 10 + x) {
      cout << x * 10 + y;
    } else {
      cout << y * 10 + x;
    }
  }
  return 0;
}
