#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d[5000], e, f[5000], g, h, i, j, k, l, m, n, o, p, q, r, s,
    t, u, v, w, x, y, z, aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll, mm, nn,
    oo, pp, qq, rr, ss, tt, uu, vv, ww, xx, yy, zz;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b;
  h = 1000000;
  i = 1000000;
  g = 1000000;
  for (c = 1; c <= a; c++) {
    cin >> d[c];
    h = min(h, d[c]);
    if (d[c] == 1) aa++;
    if (d[c] == 2) bb++;
    if (d[c] == 3) cc++;
    if (d[c] == 4) dd++;
    if (d[c] == 5) ee++;
    if (d[c] == 6) ff++;
    if (d[c] == 7) gg++;
    if (d[c] == 8) hh++;
    if (d[c] == 9) ii++;
  }
  for (e = 1; e <= b; e++) {
    cin >> f[e];
    g = min(g, f[e]);
    if (f[e] == 1) aa++;
    if (f[e] == 2) bb++;
    if (f[e] == 3) cc++;
    if (f[e] == 4) dd++;
    if (f[e] == 5) ee++;
    if (f[e] == 6) ff++;
    if (f[e] == 7) gg++;
    if (f[e] == 8) hh++;
    if (f[e] == 9) ii++;
  }
  if (aa == 2)
    cout << 1;
  else if (bb == 2)
    cout << 2;
  else if (cc == 2)
    cout << 3;
  else if (dd == 2)
    cout << 4;
  else if (ee == 2)
    cout << 5;
  else if (ff == 2)
    cout << 6;
  else if (gg == 2)
    cout << 7;
  else if (hh == 2)
    cout << 8;
  else if (ii == 2)
    cout << 9;
  else
    cout << min(h, g) << max(h, g);
}
