#include <bits/stdc++.h>
using namespace std;
int n, m, k, ans = 0, x;
int main() {
  cin >> n >> m;
  vector<int> a;
  vector<int> b;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.push_back(t);
  }
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    b.push_back(t);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int r = a[0], r1 = b[0];
  bool flag = false;
  for (int i = 0; i < m; i++) {
    if (r == b[i]) {
      cout << r << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (r1 == a[i]) {
      cout << r1 << endl;
      return 0;
    }
  }
  if (a[0] == b[0]) {
    cout << a[0] << endl;
    return 0;
  } else {
    int a = min(r, r1), b = max(r, r1);
    ans = a * 10 + b;
    cout << ans << endl;
    ;
    return 0;
  }
  return 0;
}
