#include <bits/stdc++.h>
using namespace std;
int n, m, a, x = 9, y = 9, v[15];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    x = min(x, a);
    v[a]++;
  }
  for (int i = 1; i <= m; ++i) {
    cin >> a;
    y = min(y, a);
    v[a]++;
  }
  for (int i = 1; i <= 9; i++) {
    if (v[i] == 2) {
      cout << i;
      return 0;
    }
  }
  cout << min(x, y) << max(x, y);
  return 0;
}
