#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long factorial(long long a) {
  if (a == 1) return 1;
  return a * factorial(a - 1);
}
bool ispalindrome(string s) {
  string s1 = s;
  reverse(s1.begin(), s1.end());
  if (s1.compare(s) == 0)
    return 1;
  else
    return 0;
}
void tarea() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, i, k;
  cin >> n >> m;
  int a[n], b[m];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(b, b + n);
  if (a[0] == b[0])
    cout << a[0] << "\n";
  else
    cout << min(a[0], b[0]) << max(a[0], b[0]) << "\n";
  return;
}
int main() {
  tarea();
  return 0;
}
