#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, x = INT_MAX, y = INT_MAX, z;
  cin >> n >> m;
  while (n-- && cin >> z) x = min(z, x);
  while (m-- && cin >> z) y = min(z, y);
  (x == y) ? cout << x : cout << (min(y * 10 + x, x * 10 + y));
}
