#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, e, f, g, h;
  while (cin >> a >> b) {
    int r1[20], r2[20];
    for (c = 1; c <= 9; c++) {
      r1[c] = r2[c] = 0;
    }
    for (c = 1; c <= a; c++) {
      cin >> d;
      if (c == 1) {
        e = d;
      } else {
        if (d < e) {
          e = d;
        }
      }
      r1[d]++;
    }
    for (c = 1; c <= b; c++) {
      cin >> d;
      if (c == 1) {
        f = d;
      } else {
        if (d < f) {
          f = d;
        }
      }
      r2[d]++;
    }
    h = 0;
    for (c = 1; c <= 9; c++) {
      if (r1[c] == 1 && r2[c] == 1) {
        g = c;
        h = 1;
        break;
      }
    }
    if (h == 1) {
      cout << g << endl;
    } else {
      cout << min(e, f) << max(e, f) << endl;
    }
  }
  return 0;
}
