#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, m, a[10], b[10], c[10] = {}, x = 25, y = 25;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    c[a[i]]++;
    x = min(a[i], x);
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
    c[b[i]]++;
    y = min(b[i], y);
  }
  for (i = 1; i <= 9; i++) {
    if (c[i] > 1) {
      cout << i << endl;
      return 0;
    }
  }
  cout << min(x, y) << max(x, y) << endl;
  return 0;
}
