#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n];
  int brr[m];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int j = 0; j < m; j++) cin >> brr[j];
  sort(arr, arr + n);
  sort(brr, brr + m);
  for (int i = 0; i < max(n, m); i++) {
    for (int j = 0; j < min(m, n); j++) {
      if (n >= m) {
        if (arr[i] == brr[j]) {
          cout << arr[i];
          return 0;
        }
      }
      if (n < m) {
        if (arr[j] == brr[i]) {
          cout << arr[j];
          return 0;
        }
      }
    }
  }
  cout << min(arr[0], brr[0]) << max(arr[0], brr[0]);
}
