#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, r, r1;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i] == b[j]) {
        cout << a[i] << endl;
        return 0;
      }
  r = a[0];
  r1 = b[0];
  r = r * 10 + b[0];
  r1 = r1 * 10 + a[0];
  cout << min(r, r1) << endl;
}
