#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
long long lcm(long long a, long long b) { return (a * b) / (gcd(a, b)); }
long long mpow(long long base, long long exp) {
  base %= 1000000007;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % 1000000007;
    base = (base * base) % 1000000007;
    exp >>= 1;
  }
  return result;
}
void solve() {}
long long flip(bool a, bool b, bool c, long long val) { return 0; }
int32_t main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n, m;
  cin >> n >> m;
  vector<long long> z, y;
  set<long long> z1;
  for (long long i = 0; i < n; i++) {
    long long val;
    cin >> val;
    y.push_back(val);
    z1.insert(val);
  }
  long long ans = INT_MAX;
  for (long long i = 0; i < m; i++) {
    long long val;
    cin >> val;
    z.push_back(val);
    long long a = z1.size();
    z1.insert(val);
    if (z1.size() == a) {
      if (val < ans) {
        ans = val;
      }
    }
  }
  if (z1.size() == n + m) {
    sort((y).begin(), (y).end());
    sort((z).begin(), (z).end());
    long long m1 = y[0];
    long long m2 = z[0];
    long long r = min(m1, m2), r2 = max(m1, m2);
    ans = r2;
    ans += (r * 10);
  }
  cout << ans;
  return 0;
}
