#include <bits/stdc++.h>
using namespace std;
void solve() {
  int f, s;
  cin >> f >> s;
  int a1[9];
  for (int i = 0; i < f; i++) {
    cin >> a1[i];
  }
  int a2[9];
  for (int i = 0; i < s; i++) {
    cin >> a2[i];
  }
  sort(a1, a1 + f);
  sort(a2, a2 + s);
  vector<int> its(20);
  auto b = set_intersection(a1, a1 + f, a2, a2 + s, its.begin());
  its.resize(b - its.begin());
  if (its.size() != 0) {
    cout << *its.begin() << "\n";
    return;
  }
  if (a1[0] < a2[0]) {
    cout << 10 * a1[0] + a2[0] << "\n";
  } else {
    cout << 10 * a2[0] + a1[0] << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
