#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, small1 = 10, small2 = 10, small3 = 10;
  cin >> n >> k;
  int arn[n], ark[k];
  for (int i = 0; i < n; i++) {
    cin >> arn[i];
    if (arn[i] < small1) {
      small1 = arn[i];
    }
  }
  for (int a = 0; a < k; a++) {
    cin >> ark[a];
    if (ark[a] < small2) {
      small2 = ark[a];
    }
  }
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < k; y++) {
      if (arn[x] == ark[y]) {
        small3 = ark[y];
      }
    }
  }
  if (small3 < 10) {
    cout << small3;
  } else if (small1 < small2) {
    cout << ((small1 * 10) + small2);
  } else {
    cout << ((small2 * 10) + small1);
  }
  return 0;
}
