#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s1[10] = {0}, s2[10] = {0};
  int value;
  for (int i = 0; i < n; i++) {
    cin >> value;
    s1[value] = 1;
  }
  for (int i = 0; i < m; i++) {
    cin >> value;
    s2[value]++;
  }
  int answer = 0;
  for (int digit = 1; digit <= 9 && !answer; digit++) {
    if (s1[digit] == 1 && s2[digit] == 1) {
      answer = digit;
    }
  }
  if (answer)
    cout << answer << endl;
  else {
    int a, b;
    for (a = 1; a <= 9 && s1[a] == 0; a++)
      ;
    for (b = 1; b <= 9 && s2[b] == 0; b++)
      ;
    if (a > b) swap(a, b);
    cout << a << b;
  }
  return 0;
}
