#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool mini(A &x, const B &y) {
  if (y < x) {
    x = y;
    return true;
  }
  return false;
}
template <typename A, typename B>
bool maxi(A &x, const B &y) {
  if (y > x) {
    x = y;
    return true;
  }
  return false;
}
class fastio {
 public:
  fastio() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} __fastio;
int cnta[10], cntb[10];
int main() {
  int n, m;
  cin >> n >> m;
  int ma = 9, mb = 9;
  for (auto i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnta[a]++;
  }
  for (auto i = 0; i < m; i++) {
    int a;
    cin >> a;
    cntb[a]++;
  }
  for (auto i = 1; i < 10; i++) {
    if (cnta[i] > 0 && cntb[i] > 0) {
      cout << i;
      return 0;
    }
    if (cnta[i] > 0) {
      ma = min(ma, i);
    }
    if (cntb[i] > 0) {
      mb = min(mb, i);
    }
  }
  if (ma > mb) swap(ma, mb);
  cout << ma << mb;
}
