#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  vector<int> v1(a), v2(b);
  for (int i = 0; i < a; i++) {
    cin >> v1[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> v2[i];
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  int ans = INT_MAX;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      if (v1[i] == v2[j]) {
        ans = min(ans, v1[i]);
      } else {
        ans = min(ans, v1[i] * 10 + v2[j]);
        ans = min(ans, v2[j] * 10 + v1[i]);
      }
    }
  }
  cout << ans;
  return 0;
}
