#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int> v1;
long long b[100010], c[100010];
int main() {
  int n, m, ans(100500);
  cin >> n >> m;
  v.resize(n);
  v1.resize(m);
  for (int i = 0; i < (n); ++i) {
    cin >> v[i];
  }
  for (int i = 0; i < (m); ++i) {
    cin >> v1[i];
  }
  for (int j = 0; j < (n); ++j) {
    for (int i = 0; i < (m); ++i) {
      if (v[i] == v1[j]) {
        ans = min(ans, v[i]);
      } else {
        ans = min(ans, v[i] * 10 + v1[j]);
        ans = min(ans, v1[j] * 10 + v[i]);
      }
    }
  }
  cout << ans;
}
