#include <bits/stdc++.h>
using namespace std;
int n, m, mn1 = 10, mn2 = 10, a;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (mn1 > a) mn1 = a;
  }
  for (int i = 0; i < m; i++) {
    cin >> a;
    if (mn2 > a) mn2 = a;
  }
  if (mn1 == mn2)
    cout << mn1;
  else if (mn1 > mn2)
    cout << mn2 << mn1;
  else
    cout << mn1 << mn2;
  return 0;
}
