#include <bits/stdc++.h>
using namespace std;
long long q[1234567], r[1234567], qr[1234][1234];
int main() {
  long long a, b = 2, c = 0, d = 1, e = -1, f = 0, g = 0, h = 1, i[1234567],
               j = 0, k = 1, l = 0;
  long long t = 0, z, x = 0, y, w, v = 0, u;
  double bb, cc, dd, ee, ff, gg = 101;
  string m[1234567], n, o, s, ss, nn, oo, mm[1234567];
  map<string, long long> aa;
  cin >> a >> c;
  for (b = 1; b <= a; b++) {
    cin >> r[b];
  }
  for (b = 1; b <= c; b++) {
    cin >> q[b];
  }
  sort(r + 1, r + a + 1);
  sort(q + 1, q + a + 1);
  for (b = 1; b <= a; b++) {
    for (d = 1; d <= c; d++) {
      if (r[b] == q[d]) {
        cout << r[b];
        return 0;
      }
    }
  }
  cout << r[1] << q[1];
}
