#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long factorial(long long a) {
  if (a == 1) return 1;
  return a * factorial(a - 1);
}
bool ispalindrome(string s) {
  string s1 = s;
  reverse(s1.begin(), s1.end());
  if (s1.compare(s) == 0)
    return 1;
  else
    return 0;
}
void tarea() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, i, k;
  cin >> n >> m;
  int a[n], b[m];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 1009389;
  for (i = 0; i < n; i++) {
    for (k = 0; k < m; k++) {
      if (a[i] == b[k])
        ans = min(ans, a[i]);
      else {
        ans = min(ans, (a[i] * 10) + b[k]);
        ans = min(ans, (b[k] * 10) + a[i]);
      }
    }
  }
  cout << ans << "\n";
  return;
}
int main() {
  tarea();
  return 0;
}
