#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int q = 10000000;
  int w = 10000000;
  vector<int> a1(n);
  vector<int> a2(k);
  for (int i = 0; i < n; ++i) {
    cin >> a1[i];
    if (a1[i] < q) {
      q = a1[i];
    }
  }
  for (int i = 0; i < k; ++i) {
    cin >> a2[i];
    if (a2[i] < w) {
      w = a2[i];
    }
  }
  int r = 1000000000;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      if (a1[i] == a2[j]) {
        if (r > a1[i]) {
          r = a1[i];
          int k = 1;
        }
      }
    }
  }
  if (k) {
    cout << r;
  } else if (q < w) {
    cout << q << w;
  } else {
    cout << w << q;
  }
}
