#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
int a[N];
int b[N];
bool check[10];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    check[a[i]] = true;
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  sort(b, b + m);
  sort(a, a + n);
  for (int i = 0; i < m; i++) {
    if (check[b[i]] == true) {
      cout << b[i] << endl;
      exit(0);
    }
  }
  cout << min(a[0], b[0]) << max(a[0], b[0]);
}
