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