#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int a[30], b[30];
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < m; i++) {
      scanf("%d", &b[i]);
    }
    sort(a, a + n);
    sort(b, b + m);
    if (a[0] == b[0]) {
      printf("%d\n", a[0]);
    } else {
      int t = max(a[0], b[0]), l = min(a[0], b[0]);
      t = 10 * l + t;
      printf("%d\n", t);
    }
  }
}
