#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int> f(a), s(b);
  for (int i = 0; i < a; i++) {
    cin >> f[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> s[i];
  }
  sort(f.begin(), f.end());
  sort(s.begin(), s.end());
  for (int i = 0; i < a; i++)
    for (int j = 0; j < b; j++)
      if (f[i] == s[j]) {
        cout << f[i] << endl;
        return 0;
      }
  cout << min(f[0], s[0]) << max(f[0], s[0]);
}
