#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    for (long long int(i) = (0); (i) < (n); (i)++) cin >> a[i];
    for (long long int(i) = (0); (i) < (m); (i)++) cin >> b[i];
    sort(a, a + n);
    sort(b, b + m);
    int f = 0;
    int mn;
    for (long long int(i) = (0); (i) < (n); (i)++) {
      for (long long int(j) = (0); (j) < (m); (j)++) {
        if (a[i] == b[j]) {
          mn = a[i];
          f = 1;
        }
        if (f == 1) break;
      }
    }
    if (f)
      cout << mn << "\n";
    else
      cout << min(a[0], b[0]) << max(a[0], b[0]) << "\n";
  }
}
