#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  cin >> m;
  vector<bool> a(10, false), b(10, false);
  int max1 = 10, max2 = 10;
  for (int i = 0; i != n; ++i) {
    int vr;
    cin >> vr;
    a[vr] = true;
    max1 = min(vr, max1);
  }
  for (int i = 0; i != m; ++i) {
    int vr;
    cin >> vr;
    b[vr] = true;
    max2 = min(max2, vr);
  }
  for (int i = 1; i != 11; ++i) {
    if (a[i] == true && b[i] == true) {
      cout << i;
      return 0;
    }
  }
  if (max1 > max2) swap(max1, max2);
  cout << max1 * 10 + max2;
  return 0;
}
