#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  int x[10];
  for (int i = 0; i < 10; i++) x[i] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x[a[i]]++;
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    x[b[i]]++;
  }
  for (int i = 0; i < 10; i++) {
    if (x[i] == 2) {
      cout << i << endl;
      return 0;
    }
  }
  sort(a, a + n);
  sort(b, b + m);
  int x1 = min(a[0], b[0]);
  int y = max(a[0], b[0]);
  int ans = 10 * x1 + y;
  cout << ans << endl;
  return 0;
}
