#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> v1(n), v2(m);
  for (int i = 0; i < n; ++i) cin >> v1[i];
  for (int i = 0; i < m; ++i) cin >> v2[i];
  int mn1 = *min_element(v1.begin(), v1.end()),
      mn2 = *min_element(v2.begin(), v2.end());
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (v2[i] == v1[j]) {
        cout << v2[i] << endl;
        return;
      }
    }
  }
  cout << min(mn1, mn2) << max(mn1, mn2) << endl;
  return;
}
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
