#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int x, y;
  set<int> a, b;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.insert(x);
  }
  for (int i = 0; i < m; i++) {
    cin >> y;
    b.insert(y);
  }
  int ans = 100;
  x = *a.begin();
  if (b.find(x) != b.end()) ans = min(ans, x);
  y = *b.begin();
  if (a.find(y) != a.end()) ans = min(ans, y);
  if (x == y) ans = min(ans, x);
  ans = min(ans, min(x, y) * 10 + max(x, y));
  cout << ans;
  return 0;
}
