#include <bits/stdc++.h>
using namespace std;
int n, m, p;
vector<int> mas;
vector<int> mas1;
int main() {
  cin >> n >> m;
  mas.resize(n);
  mas1.resize(m);
  for (int i = 0; i < n; i++) {
    cin >> p;
    mas[i] = p;
  }
  for (int i = 0; i < m; i++) {
    cin >> p;
    mas1[i] = p;
  }
  sort(mas.begin(), mas.end());
  sort(mas1.begin(), mas1.end());
  if (mas[0] != mas1[0])
    cout << mas[0] << mas1[0];
  else
    cout << mas[0];
}
