#include <bits/stdc++.h>
using namespace std;
bool prime(long long n) {
  if (n < 2) return false;
  for (long long x = 2; x * x <= n; x++) {
    if (n % x == 0) return false;
  }
  return true;
}
bool isPerfectSquare(long double x) {
  if (x >= 0) {
    long long sr = sqrt(x);
    return (sr * sr == x);
  }
  return false;
}
bool sortBySec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
bool sortBySecDesc(const pair<long long, long long> &a,
                   const pair<long long, long long> &b) {
  return a.second > b.second;
}
string decimalToBinary(long long n) {
  string s = bitset<64>(n).to_string();
  const auto loc1 = s.find('1');
  if (loc1 != string::npos) return s.substr(loc1);
  return "0";
}
long long binaryToDecimal(string n) {
  string num = n;
  long long dec_value = 0;
  long long base = 1;
  long long len = num.length();
  for (long long i = len - 1; i >= 0; i--) {
    if (num[i] == '1') dec_value += base;
    base = base * 2;
  }
  return dec_value;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
void solve() {
  long long n;
  long long m;
  cin >> n >> m;
  long long a[10];
  long long b[10];
  for (long long i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < (m); ++i) {
    cin >> b[i];
  }
  sort(a, a + n);
  sort(b, b + m);
  long long n1;
  long long n2;
  long long v;
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      if (a[i] == b[j]) {
        n1 = a[i];
        break;
      }
    }
  }
  if (min(a[0], b[0]) == a[0]) {
    v = (a[0] * 10 + b[0]);
  } else {
    v = (b[0] * 10 + a[0]);
  }
  cout << min(n1, v) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
