#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a = 10, b = 10;
  set<int> s;
  while (n--) {
    int x;
    cin >> x;
    s.insert(x);
    a = min(a, x);
  }
  int ans = INT_MAX;
  while (m--) {
    int x;
    cin >> x;
    if (s.count(x)) {
      ans = min(ans, x);
    }
    b = min(b, x);
  }
  if (ans == INT_MAX)
    cout << min(a, b) << max(a, b) << '\n';
  else
    cout << ans << '\n';
  return 0;
}
