#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[20], b[20], n, i, m, j, flag = 1;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (j = 0; j < m; j++) cin >> b[j];
  sort(b, b + m);
  i = j = 0;
  while (i < n && j < m && flag) {
    if (a[i] == b[j]) {
      cout << a[i];
      flag = 0;
      break;
    } else if (a[i] > b[j])
      j++;
    else
      i++;
  }
  if (flag) {
    int s = min(a[0], b[0]) * 10 + max(a[0], b[0]);
    cout << s;
  }
}
