#include <bits/stdc++.h>
using namespace std;
int n, m, a[10], b[10], aux;
bool flag[2][10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i], flag[0][a[i]] = 1;
  for (int j = 0; j < m; j++) cin >> b[j], flag[1][b[j]] = 1;
  sort(a, a + n);
  sort(b, b + m);
  for (int i = 1; i < 10; i++)
    if (flag[0][i] && flag[1][i] && !aux) aux = i;
  if (aux) {
    cout << aux;
  } else if (a[0] < b[0]) {
    cout << a[0] << b[0];
  } else
    cout << b[0] << a[0];
}
