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