#include <bits/stdc++.h>
using namespace std;
int a[100];
int b[100];
bool u1[100];
bool u2[100];
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    u1[a[i]] = 1;
  }
  for (int j = 1; j <= m; j++) {
    cin >> b[j];
    u2[b[j]] = 1;
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  int k = -1;
  for (int i = 1; i <= 9; i++) {
    if (u1[i] == 1 and u2[i] == 1) {
      k = a[i];
      break;
    }
  }
  if (k != -1) {
    cout << k;
  } else
    cout << min(a[1], b[1]) * 10 + max(a[1], b[1]);
  return 0;
}
