#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  while (cin >> n >> m) {
    long long a[n], b[m], ma = LLONG_MAX, mi = LLONG_MAX;
    long long fre[10] = {0};
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      ma = min(a[i], ma);
      fre[a[i]]++;
    }
    for (long long i = 0; i < m; i++) {
      cin >> b[i];
      mi = min(b[i], mi);
      fre[b[i]]++;
    }
    int result = 0;
    for (long long i = 0; i < 10; i++)
      if (fre[i] == 2) {
        result = i;
        break;
      }
    if (result)
      cout << result << endl;
    else {
      if (ma > mi) swap(ma, mi);
      if (ma == mi)
        cout << ma << endl;
      else
        cout << ma << mi << endl;
    }
  }
  return 0;
}
