#include <bits/stdc++.h>
using namespace std;
vector<long long int> ve;
stack<long long int> st;
set<long long int> se;
map<long long int, long long int> mp;
int a[1000007];
int b[1000007];
long long int _na(char a) {
  if (a == 'u' || a == 'e' || a == 'o' || a == 'a' || a == 'i' || a == 'y') {
    return 1;
  } else {
    return 0;
  }
}
long long int _gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return _gcd(b, a % b);
}
long long int _nt(long long int n) {
  if (n < 2)
    return 0;
  else
    for (int i = 2; i * i <= n; i++)
      if (n % i == 0) return 0;
  return 1;
}
long long int _pm(long long int a, long long int n, long long int m) {
  if (n == 0) return 1 % m;
  if (n == 1) return a % m;
  long long int t = _pm(a, n / 2, m) % m;
  t = (t * t) % m;
  if (n % 2) t = (t * a) % m;
  return t % m;
}
int main() {
  long long int n;
  cin >> n;
  long long int m;
  cin >> m;
  long long int xi, li;
  int res = INT_MAX, res2 = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    res = min(a[i], res);
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    res2 = min(res2, b[i]);
  }
  if (res2 == res) {
    cout << res2 << "\n";
  } else if (res2 > res) {
    cout << res << res2 << "\n";
  } else if (res > res2) {
    cout << res2 << res << "\n";
  }
  return 0;
}
