#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> used(10, 0);
  int mn = INF, mm = INF;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    used[x] = 1;
    mn = min(x, mn);
  }
  int mans = INF;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    if (used[x]) {
      mans = min(mans, x);
    }
    mm = min(mm, x);
  }
  if (mm > mn) {
    swap(mm, mn);
  }
  cout << min(mans, mm * 10 + mn);
}
