#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 11111, ans1 = 11111;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  for (int i = 0; i < n; i++) {
    for (int tm, j = 0; j < m; j++) {
      if (a[i] == b[j])
        tm = a[i];
      else
        tm = (a[i] * 10) + b[j];
      if (ans > tm) ans = tm;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int tm, j = 0; j < n; j++) {
      if (a[j] == b[i])
        tm = a[j];
      else
        tm = (b[i] * 10) + a[j];
      if (ans1 > tm) ans1 = tm;
    }
  }
  if (ans < ans1)
    cout << ans;
  else
    cout << ans1;
  return 0;
}
