#include <bits/stdc++.h>
using namespace std;
bool f[10];
int main(int argc, char** argv) {
  int N, M, a, b, x;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (!i)
      a = x;
    else
      a = min(a, x);
  }
  int ok = 10;
  for (int i = 0; i < M; i++) {
    cin >> x;
    if (!i)
      b = x;
    else
      b = min(b, x);
    if (f[x]) ok = min(ok, x);
  }
  if (ok != 10)
    cout << ok << endl;
  else
    cout << min(a, b) << max(a, b) << endl;
  return 0;
}
