#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[n], b[m], c = 0, d = 0, e;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int cnt = 0, cnt1 = 0;
  sort(a, a + n);
  sort(b, b + m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        c = a[i];
        cnt++;
      }
    }
    if (cnt == 1) {
      break;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (b[j] == a[i]) {
        d = b[j];
        cnt1++;
      }
    }
    if (cnt1 == 1) {
      break;
    }
  }
  if (a[0] == b[0]) {
    e = a[0];
  }
  if (a[0] > b[0]) {
    e = b[0] * 10 + a[0];
  }
  if (a[0] < b[0]) {
    e = a[0] * 10 + b[0];
  }
  if (c <= d && c <= e && c != 0) {
    cout << c << '\n';
  } else if (d <= c && d <= e && d != 0) {
    cout << d << '\n';
  } else {
    cout << e << '\n';
  }
  return 0;
}
