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