#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int a[N], b[N];
int n, m;
int main() {
  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);
  bool flag = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        cout << a[i] << endl;
        flag = true;
        break;
      }
    }
    if (flag) break;
  }
  if (!flag) cout << min(a[0], b[0]) << max(a[0], b[0]) << endl;
  return 0;
}
