#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, e = 10, r = 10, k;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    if (k < e) e = k;
  }
  for (int i = 1; i <= m; i++) {
    cin >> k;
    if (k < r) r = k;
  }
  if (e == r) {
    cout << e;
    return 0;
  }
  if (e < r) {
    cout << e << r;
    return 0;
  } else {
    cout << r << e;
    return 0;
  }
}
