#include <bits/stdc++.h>
using namespace std;
int solve(vector<int>& l1, vector<int>& l2, int n, int m) {
  int val1 = *min_element(l1.begin(), l1.end());
  int val2 = *min_element(l2.begin(), l2.end());
  if (val1 == val2) return val1;
  int c = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (l1[i] == l2[j]) c = min(c, l1[i]);
    }
  }
  int num1 = val1 * 10 + val2;
  int num2 = val2 * 10 + val1;
  return min({num1, num2, c});
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> l1(n);
  vector<int> l2(m);
  for (int i = 0; i < n; i++) cin >> l1[i];
  for (int i = 0; i < m; i++) cin >> l2[i];
  cout << solve(l1, l2, n, m) << endl;
  return 0;
}
