#include <bits/stdc++.h>
using namespace std;
const long long MXN = 1e5 + 1;
const long long MOD = 1e9 + 7;
long long a[MXN], b[MXN];
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, mn = 10, mn1 = 10;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v.push_back(a[i]);
    mn = min(mn, a[i]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    v.push_back(b[i]);
    mn1 = min(mn1, b[i]);
  }
  sort((v).begin(), (v).end());
  for (int i = 0; i < (int)(v).size(); i++) {
    if (v[i] == v[i - 1]) {
      cout << v[i];
      return 0;
    }
  }
  cout << min(mn, mn1) << max(mn, mn1);
  return 0;
}
