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