#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans = 654;
vector<int> a, b, us(10);
int main() {
  cin >> n >> m;
  a.resize(n);
  b.resize(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    us[a[i]] = 1;
  }
  for (int j = 0; j < m; ++j) {
    cin >> b[j];
    if (us[b[j]] == 1) {
      ans = min(ans, b[j]);
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << min({(a[0] * 10) + b[0], (b[0] * 10) + a[0], ans});
}
