#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y, ind;
  char ch;
};
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long fact[13];
void factorial() {
  fact[0] = 1;
  for (long long i = 1; i < 12; i++) fact[i] = (fact[i - 1] * i);
}
vector<long long> sie;
long long spf[5000001 + 7];
void sieve() {
  for (long long i = 2; i < 5000001; i++) {
    if (spf[i] == 0) {
      spf[i] = i;
      sie.push_back(i);
    }
    for (long long j = 0; j < ((long long)(sie).size()) &&
                          i * sie[j] <= 5000001 && sie[j] <= spf[i];
         j++)
      spf[i * sie[j]] = sie[j];
  }
}
bool cmp(point A, point B) {
  if (A.x != B.x) return A.x < B.x;
  return A.y < B.y;
}
long long n, m, _, ans, __;
vector<long long> adj[300005];
string st;
long long ind[300005];
long long bfs(long long s) {
  long long lev[n];
  memset(lev, 0, sizeof(lev));
  queue<long long> dq;
  dq.push(s);
  long long an = 1;
  lev[s] = 1;
  while (!dq.empty()) {
    long long u = dq.front();
    for (long long i = 0; i < ((long long)(adj[u]).size()); i++) {
      long long v = adj[u][i];
      dq.push(v);
      lev[v] = lev[u];
      if (st[v] == st[s]) lev[v]++;
    }
    an = max(an, lev[u]);
    dq.pop();
  }
  return an;
}
bool cycle() {
  queue<long long> q;
  vector<long long> top;
  long long cou = 0;
  for (long long i = 0; i < n; i++)
    if (!ind[i]) q.push(i);
  while (!q.empty()) {
    long long d = q.front();
    q.pop();
    top.push_back(d);
    for (long long i = 0; i < ((long long)(adj[d]).size()); i++)
      if (--ind[adj[d][i]] == 0) q.push(adj[d][i]);
    cou++;
  }
  if (n != cou) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(12);
  cin >> n >> m;
  long long a = 18, b = 88;
  for (long long i = 0; i < n; i++) {
    cin >> _;
    a = min(_, a);
  }
  for (long long i = 0; i < m; i++) {
    cin >> _;
    b = min(_, b);
  }
  if (a == b)
    cout << a << "\n";
  else if (a < b) {
    cout << a;
    cout << b << "\n";
  } else {
    cout << b;
    cout << a << "\n";
  }
  return 0;
}
