#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a[11], b[11], v[11];
  cin >> n >> m;
  memset(v, 0, sizeof(v));
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    v[a[i]]++;
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    v[b[i]]++;
  }
  for (int i = 1; i <= 9; ++i) {
    if (v[i] == 2) {
      cout << i << endl;
      return 0;
    }
  }
  sort(a, a + n);
  sort(b, b + n);
  cout << min(a[0], b[0]) << max(a[0], b[0]) << endl;
  return 0;
}
