#include <bits/stdc++.h>
using namespace std;
int main() {
  bool flag = 0;
  int m, n;
  cin >> m >> n;
  bool a[10];
  for (int i = 0; i < 10; i++) a[i] = 0;
  bool b[10];
  for (int i = 0; i < 10; i++) b[i] = 0;
  for (int i = 0; i < m; i++) {
    int r;
    cin >> r;
    a[r] = 1;
  }
  for (int i = 0; i < n; i++) {
    int r;
    cin >> r;
    b[r] = 1;
  }
  for (int i = 0; i < 10; i++) {
    bool w = a[i] & b[i];
    if (w) {
      cout << w;
      flag = 1;
      break;
    }
  }
  int e, r;
  if (!flag) {
    for (int i = 0; i < 10; i++) {
      if (a[i] == 1) {
        e = i;
        break;
      }
    }
    for (int i = 0; i < 10; i++) {
      if (b[i] == 1) {
        r = i;
        break;
      }
    }
    if (e > r) {
      cout << r << e;
    } else {
      cout << e << r;
    }
  }
  return 0;
}
