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