#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5;
long long n, m, a, c, mn = 1e9;
vector<long long> v1, v2;
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    v1.push_back(a);
  }
  for (long long i = 0; i < m; i++) {
    cin >> a;
    v2.push_back(a);
  }
  for (long long i = 0; i < v1.size(); i++) {
    for (long long j = 0; j < v2.size(); j++) {
      if (v1[i] == v2[j]) {
        if (mn > v1[i]) {
          mn = v1[i];
        }
      }
    }
  }
  if (mn != 1e9) {
    cout << mn;
  } else {
    for (long long i = 0; i < v1.size(); i++) {
      for (long long j = 0; j < v2.size(); j++) {
        c = v1[i] * 10 + v2[j];
        if (c < mn) {
          mn = c;
        }
      }
    }
    cout << mn;
  }
  cout << "\n";
  return 0;
}
