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