#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  if (b) return GCD(b, a % b);
  return a;
}
bool u1[10];
bool u2[10];
int main() {
  long long n, m, v;
  vector<long long> a, b;
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> v;
    a.push_back(v);
    u1[v] = true;
  }
  for (long long i = 0; i < m; i++) {
    cin >> v;
    b.push_back(v);
    u2[v] = true;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (long long i = 1; i <= 9; i++) {
    if (u1[i] && u2[i]) {
      cout << i;
      return 0;
    }
  }
  if (a[0] < b[0]) {
    cout << a[0] << b[0];
  } else
    cout << b[0] << a[0];
}
