#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (auto &x : a) cin >> x;
  for (auto &x : b) cin >> x;
  sort(a, a + n), sort(b, b + n);
  if (a[0] == b[0])
    cout << a[0] << endl;
  else {
    if (a[0] == 0 || b[0] == 0)
      cout << a[0] + b[0] << 0 << endl;
    else
      cout << min(a[0], b[0]) << max(a[0], b[0]) << endl;
  }
}
