#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m;
  vector<int> a;
  vector<int> b;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    a.push_back(k);
  }
  for (int i = 1; i <= m; i++) {
    cin >> k;
    b.push_back(k);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (a[0] == b[0] && a[0] != 0) {
    cout << a[0];
    return 0;
  }
  if (a[0] == b[0] && a[0] == 0) {
    cout << min(a[1], b[1]) << 0;
    return 0;
  }
  cout << min(a[0], b[0]) << max(a[0], b[0]);
}
