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