#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> dig1, dig2;
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    dig1.push_back(x);
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    dig2.push_back(x);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (dig1[i] == dig2[j])
        ans = min(ans, dig1[i]);
      else {
        ans = min(ans, 10 * dig1[i] + dig2[j]);
        ans = min(ans, 10 * dig2[j] + dig1[i]);
      }
    }
  cout << ans << endl;
}
