#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a[15];
  int b[15];
  while (~scanf("%d%d", &n, &m)) {
    int ta[15] = {0};
    int tb[15] = {0};
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      ta[a[i]]++;
    }
    for (int i = 0; i < m; i++) {
      scanf("%d", &b[i]);
      tb[b[i]]++;
    }
    int ans = 0x3f3f3f3f;
    int fa = -1;
    int fb = -1;
    for (int i = 1; i <= 9; i++) {
      if (ta[i] != 0 && fa == -1) fa = i;
      if (tb[i] != 0 && fb == -1) fb = i;
      if (ta[i] != 0 && tb[i] != 0) ans = min(ans, i);
    }
    ans = min(ans, 10 * fa + fb);
    ans = min(ans, 10 * fb + fa);
    printf("%d\n", ans);
  }
  return 0;
}
