#include <bits/stdc++.h>
using namespace std;
const int N = 600, oo = 2e9;
int nn[N], mm[N], n, m;
int check() {
  int mn = oo;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (nn[i] == mm[j]) mn = min(mn, nn[i]);
    }
  }
  if (mn == oo) return -1;
  return mn;
}
int main() {
  ios::sync_with_stdio(false);
  int mn1 = oo, mn2 = oo, mnb1 = oo, mnb2 = oo;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> nn[i];
    mn1 = min(mn1, nn[i]);
    if (nn[i]) mnb1 = min(mnb1, nn[i]);
  }
  for (int i = 0; i < m; ++i) {
    cin >> mm[i];
    mn2 = min(mn2, mm[i]);
    if (mm[i]) mnb2 = min(mnb2, mm[i]);
  }
  int mini = min(mn1, mn2), maxi = max(mn1, mn2);
  if (check() != -1)
    cout << check();
  else if (!mn1) {
    cout << min(mn2 * 10, mnb1 * 10 + mn2);
  } else if (!mn2)
    cout << min(mn1 * 10, mnb2 * 10 + mn1);
  else
    cout << mini * 10 + maxi;
  return 0;
}
