#include <bits/stdc++.h>
using namespace std;
const long long len = 10001;
int main() {
  int n, m;
  cin >> n >> m;
  int i;
  int a[len], b[len];
  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);
  int j, w = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++)
      if (a[i] == b[j]) {
        w = 1;
        goto u;
      }
  }
u:;
  if (w == 0) {
    if (a[0] >= b[0])
      cout << b[0] << a[0] << endl;
    else if (a[0] < b[0])
      cout << a[0] << b[0] << endl;
  } else
    cout << a[i] << endl;
  return 0;
}
