#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int minim1 = 100, minim2 = 100;
  vector<int> v(100, 0);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    minim1 = min(x, minim1);
    v[x]++;
  }
  for (int i = 1; i <= m; ++i) {
    int x;
    cin >> x;
    minim2 = min(x, minim2);
    v[x]++;
  }
  for (int i = 1; i <= 9; ++i) {
    if (v[i] == 2) {
      cout << i;
      return 0;
    }
  }
  cout << min(minim1, minim2);
  cout << minim1 + minim2 - min(minim1, minim2);
  return 0;
}
