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