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