#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);
  set_intersection(a1, a1 + f, a2, a2 + s, its.begin());
  if (its.size() != 0) {
    cout << *its.begin() << "\n";
    return;
  }
  cout << 10 * a1[0] + a2[0] << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
