#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ma = 10, mb = 10;
  int x, y, a[10], b[10];
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x] = 1;
    ma = min(x, ma);
  }
  for (int i = 1; i <= m; i++) {
    cin >> y;
    b[y] = 1;
    mb = min(y, mb);
  }
  for (int i = 1; i <= 9; i++) {
    if (a[i] && b[i]) {
      cout << i << endl;
      return 0;
    }
  }
  cout << min(ma, mb) << max(ma, mb) << endl;
  return 0;
}
