#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, t, min, max, j, a[10], i, b[10];
  cin >> n >> 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++)
    for (j = 1; j <= m; j++)
      if (a[i] == b[j]) {
        cout << a[i];
        return 0;
      }
  for (i = 1; i < n; i++)
    for (j = i + 1; j <= n; j++)
      if (a[i] > a[j]) {
        t = a[i];
        a[i] = a[j];
        a[j] = t;
      }
  for (i = 1; i < m; i++)
    for (j = i + 1; j <= m; j++)
      if (b[i] > b[j]) {
        t = b[i];
        b[i] = b[j];
        b[j] = t;
      }
  if (a[1] == b[1])
    cout << a[1];
  else {
    if (a[1] > b[1]) {
      max = a[1];
      min = b[1];
    } else {
      max = b[1];
      min = a[1];
    }
    cout << 10 * min + max;
  }
  return 0;
}
