#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[10];
  int b[10];
  int n, m, i, j, min = 100;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i] == b[j] && a[i] < min) {
        min = a[i];
      }
      if (a[i] > b[j] && (b[j] * 10 + a[i]) < min) {
        min = (b[j] * 10 + a[i]);
      }
      if (a[i] < b[j] && (a[i] * 10 + b[j]) < min) {
        min = (a[i] * 10 + b[j]);
      }
    }
  }
  cout << min;
  return 0;
}
