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