#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i;
  cin >> n >> m;
  int a[n], b[m];
  map<int, int> mp, mp2;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]] = 1;
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
    mp2[b[i]] = 1;
  }
  sort(a, a + n);
  sort(b, b + m);
  for (i = 1; i <= 9; i++) {
    if (mp[i] == 1 && mp2[i] == 1) {
      cout << i << endl;
      return 0;
    }
  }
  if (a[0] > b[0]) {
    swap(a[0], b[0]);
  }
  cout << a[0] << b[0] << endl;
  return 0;
}
