#include <bits/stdc++.h>
using namespace std;
bool isd;
int ms = 1;
const int N = 150;
int s(int a) {
  int sum = 0;
  while (a > 0) {
    sum += a % 10;
    a /= 10;
  }
  return sum;
}
int main() {
  int n;
  int m;
  cin >> n >> m;
  vector<int> mas(n);
  vector<int> ass(m);
  for (int i = 0; i < n; i++) {
    cin >> mas[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> ass[i];
  }
  sort(mas.begin(), mas.end());
  sort(ass.begin(), ass.end());
  int min = 10000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mas[i] == ass[j]) {
        cout << mas[i];
        return 0;
      }
    }
  }
  if (mas[0] < ass[0])
    cout << mas[0] << ass[0];
  else if (ass[0] < mas[0])
    cout << ass[0] << mas[0];
  else
    cout << mas[0];
  return 0;
}
