#include <bits/stdc++.h>
using namespace std;
set<long long> st;
vector<int> v, v2, vv;
string ss, tt, s1, s2, s3;
char q, w;
char s[11], s4[11];
int idx[4] = {0, 1, 0, -1};
int idy[4] = {1, 0, -1, 0};
bool ic, cn, dc, hal;
int arr[128];
int n, x, y, d, m, t, a, b, c, res, cnt, tmp, mx = 0, mn = 1e9, sz, ty, tu;
bool srt(pair<string, int>& a, pair<string, int>& b) {
  return a.second > b.second;
}
bool isPal(string s) {
  int sz = s.size();
  for (int i = 0; i < sz / 2; ++i) {
    if (s[i] != s[sz - i - 1]) return false;
  }
  return true;
}
int main() {
  a = 10;
  b = 10;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &t);
    v.push_back(t);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d", &t);
    v2.push_back(t);
  }
  sort((v).begin(), (v).end());
  sort((v2).begin(), (v2).end());
  if (find((v2).begin(), (v2).end(), v[0]) != v2.end()) {
    printf("%d", v[0]);
  } else if (find((v).begin(), (v).end(), v2[0]) != v.end()) {
    printf("%d", v2[0]);
  } else {
    printf("%d%d", min(v[0], v2[0]), max(v[0], v2[0]));
  }
  return 0;
}
