#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7;
const long long MN = 1e9 + 7;
const long long MX = -1e9 - 7;
long long n, m, x, c, mn1 = MN, mn2 = MN;
string s, s1;
vector<long long> a, b;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x < mn1) mn1 = x;
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    if (x < mn2) mn2 = x;
  }
  if (mn1 == mn2)
    cout << mn1;
  else
    cout << min(mn1, mn2) << max(mn1, mn2);
  cout << "\n";
  return 0;
}
