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