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