#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x = 10, y = 10, in;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> in;
    x = min(x, in);
  }
  for (int i = 0; i < m; i++) {
    cin >> in;
    y = min(y, in);
  }
  if (x != y)
    cout << min(x, y) << max(x, y) << '\n';
  else
    cout << min(x, y) << '\n';
  return 0;
}
