#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(m);
  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  long long mn = 1e18;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        mn = min(mn, a[i]);
      } else {
        long long op = min(a[i], b[j]), op2 = max(a[i], b[j]);
        long long V = op * 10 + op2;
        mn = min(mn, V);
      }
    }
  }
  cout << mn;
}
