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