#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a = 10, b = 10;
  while (n--) {
    int x;
    cin >> x;
    a = min(a, x);
  }
  while (m--) {
    int x;
    cin >> x;
    b = min(b, x);
  }
  if (a == b)
    cout << a << '\n';
  else
    cout << a << b << '\n';
  return 0;
}
