#include <bits/stdc++.h>
using namespace std;
int a[10], b[10];
int main() {
  int x, y;
  while (scanf("%d%d", &x, &y) != EOF) {
    int ans = 1000, ok = 0;
    for (int i = 0; i < x; i++) scanf("%d", &a[i]);
    for (int i = 0; i < y; i++) scanf("%d", &b[i]);
    for (int i = 0; i < x; i++)
      for (int j = 0; j < y; j++) {
        if (a[i] == b[j] && a[i] < ans) ans = a[i];
        if (a[i] * 10 + b[j] < ans) ans = a[i] * 10 + b[j];
        if (b[j] * 10 + a[i] < ans) ans = b[j] * 10 + a[i];
      }
    printf("%d\n", ans);
  }
  return 0;
}
