#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[9], b[9];
  int i, n, m;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < m; i++) cin >> b[i];
  int m1 = 9, m2 = 9;
  for (i = 0; i < n; i++)
    if (a[i] < m1) m1 = a[i];
  for (i = 0; i < m; i++)
    if (b[i] < m2) m2 = b[i];
  int num;
  if (m1 == m2)
    num = m1;
  else if (m1 > m2)
    num = 10 * m2 + m1;
  else
    num = 10 * m1 + m2;
  cout << num;
  return 0;
}
