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