#include <bits/stdc++.h>
using namespace std;
const int maxnm = 9 + 20;
int n = 0, m = 0, a[maxnm], b[maxnm], g = 1000;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  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] && a[i] < g) {
        g = a[i];
      } else if (a[i] > b[j] && (b[i] * 10 + a[i]) < g) {
        g = b[j] * 10 + a[i];
      } else if (b[j] > a[i] && (a[i] * 10 + b[j]) < g) {
        g = a[i] * 10 + b[j];
      }
    }
  }
  cout << g;
  return 0;
}
