#include <bits/stdc++.h>
using namespace std;
int x[10], y[10], n, m, a, b, c, t, tt;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    x[a]++;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a;
    y[a]++;
  }
  for (int i = 1; i <= 9; i++) {
    if (x[i] >= 1 && t == 0) b = i, t++;
    if (y[i] >= 1 && tt == 0) c = i, tt++;
  }
  if (b == c) {
    cout << b << endl;
    return 0;
  } else {
    cout << min(b, c) * 10 + max(b, c) << endl;
    return 0;
  }
  return 0;
}
