#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e8;
int ToggleBit(int n, int X) { return n ^ (1 << X); }
int SetBit(int n, int X) { return n | (1 << X); }
int ClearBit(int n, int X) { return n & ~(1 << X); }
bool CheckBit(int n, int X) { return (bool)(n & (1 << X)); }
int main() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  map<long long, long long> mp;
  long long mn1 = INT_MAX, mn2 = INT_MAX, x;
  {
    for (int i = 0; i < n; i++) {
      scanf("%lld", &x);
      mn1 = min(x, mn1);
      mp[x]++;
    }
    for (int i = 0; i < m; i++) {
      scanf("%lld", &x);
      mn2 = min(x, mn2);
      mp[x]++;
    }
    for (int i = 0; i < 10; i++) {
      if (mp[i] > 1) {
        printf("%lld\n", i);
        return 0;
      }
    }
    printf("%lld\n", (min(mn1, mn2) * 10 + max(mn1, mn2)));
  }
  return 0;
}
