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