#include <bits/stdc++.h>
using namespace std;
int t[15];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, a;
  cin >> n >> m;
  int mini = INT_MAX, mini2 = INT_MAX, ind = 20;
  for (int i = 0; i < n; i++) {
    cin >> a;
    t[a]++;
    mini = min(mini, a);
  }
  for (int i = 0; i < m; i++) {
    cin >> a;
    t[a]++;
    if (t[a] >= 2) {
      ind = min(ind, a);
    }
    mini2 = min(mini2, a);
  }
  if (ind != 20)
    cout << ind << endl;
  else
    cout << min(mini * 10 + mini2, mini2 * 10 + mini) << endl;
  return 0;
}
