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