#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  vector<long long int> a(n, 0);
  vector<long long int> b(m, 0);
  vector<long long int> freq(10, 0);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    freq[a[i]]++;
  }
  for (long long int i = 0; i < m; i++) {
    cin >> b[i];
    freq[b[i]]++;
  }
  for (long long int i = 1; i <= 9; i++) {
    if (freq[i] > 1) {
      cout << i;
      return 0;
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << min(a[0], b[0]) << max(a[0], b[0]);
}
