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