#include <bits/stdc++.h>
using namespace std;
const int N = 100011;
const int oo = 2e9;
const int LOGN = 18;
int n, m, a[10], b[10];
int mn = 1e9;
void merge(int a, int b) {
  int num = a * 10 + b;
  if (a == b) num = a;
  if (num < mn) mn = num;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int j = 0; j < m; ++j) cin >> b[j];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      merge(a[i], b[j]);
      merge(b[j], a[i]);
    }
  }
  cout << mn << endl;
  return 0;
}
