#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long int N, M;
  cin >> N >> M;
  vector<long long int> a(N);
  for (long long int i = (0); i < (long long int)(N); ++i) cin >> a[i];
  vector<long long int> b(N);
  for (long long int i = (0); i < (long long int)(N); ++i) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int f = -1;
  for (long long int i = (0); i < (long long int)(a.size()); ++i)
    for (long long int j = (0); j < (long long int)(b.size()); ++j)
      if (a[i] == b[i]) {
        f = a[i];
        goto end;
      }
end:
  if (f != -1)
    cout << f << endl;
  else
    cout << (min(a[0], b[0])) << (max(a[0], b[0])) << endl;
  return 0;
}
