#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const long long MAXN = 1000001;
const long long MAXVAL = 5000000;
const long long INF = (long long)1e17 + 100;
const long long MOD = (long long)1e9 + 7;
string failMessage;
void fail() {
  cout << failMessage;
  exit(0);
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void solve() {
  int n, m;
  cin >> n >> m;
  set<int> a, b;
  for (int i = 0; i < n; i++) {
    int u;
    cin >> u;
    a.insert(u);
  }
  for (int j = 0; j < m; j++) {
    int u;
    cin >> u;
    b.insert(u);
  }
  for (auto now : a) {
    if (b.find(now) != b.end()) {
      cout << now;
      exit(0);
    }
  }
  cout << min(*a.begin() * 10 + *b.begin(), *b.begin() * 10 + *a.begin());
}
int main() {
  const string FILENAME = "input";
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  solve();
}
