#include <bits/stdc++.h>
using namespace std;
int n, m, a[10], b[10], td[10], mina = 1e9, minb = 1e9;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mina = min(mina, a[i]);
    td[a[i]]++;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    minb = min(minb, b[i]);
    td[b[i]]++;
  }
  for (int i = 1; i <= 9; i++)
    if (td[i] == 2) {
      cout << i;
      return 0;
    }
  if (mina > minb)
    cout << minb << mina;
  else
    cout << mina << minb;
}
