#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
int primes[100000];
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> arr1(n), arr2(m);
  for (int i = 0; i < n; i++) {
    cin >> arr1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> arr2[i];
  }
  sort(arr1.begin(), arr1.end());
  sort(arr2.begin(), arr2.end());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr1[i] == arr2[j]) {
        cout << arr1[i] << endl;
        goto end;
      }
    }
  }
  cout << min(arr1[0], arr2[0]) << max(arr1[0], arr2[0]) << endl;
end:
  return 0;
}
