#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s1m = 9;
  int s2m = 9;
  vector<int> str1(9);
  vector<int> str2(9);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> str1[i];
    if (s1m > str1[i]) s1m = str1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> str2[i];
    if (s2m > str2[i]) s2m = str2[i];
  }
  if (s1m == s2m) {
    cout << s1m;
    return 0;
  }
  (s1m > s2m) ? (cout << s2m << s1m) : (cout << s1m << s2m);
  return 0;
}
