#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, cnt = 100500;
vector<int> vc, vb;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a;
    vc.push_back(a);
  }
  for (int i = 0; i < m; i++) {
    cin >> b;
    vb.push_back(b);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vc[i] == vb[j]) {
        cnt = min(cnt, vc[i]);
      } else {
        cnt = min(cnt, vc[i] * 10 + vb[j]);
        cnt = min(cnt, vb[j] * 10 + vc[i]);
      }
    }
  }
  cout << cnt;
}
