#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, ans, a[10], b[10];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (j = 1; j <= m; j++) cin >> b[j];
  ans = 100500;
  for (i = 1; i <= n; i++)
    for (j = 1; 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 << endl;
  return 0;
}
