#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m], i, c = 0, j, d, e;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < m; i++) cin >> b[i];
  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]) {
        cout << a[i];
        c = 1;
        break;
      }
      if (c == 1) break;
    }
  }
  if (c == 0) {
    if (a[0] >= b[0])
      cout << b[0] << a[0];
    else
      cout << a[0] << b[0];
  }
}
