#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int add(int a, int b) {
  long long x = a + b;
  if (x >= 1000000007) x -= 1000000007;
  if (x < 0) x += 1000000007;
  return x;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long pw(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed() {
  long long a = rng();
  return a;
}
int n, m, has1[22], has2[22];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    has1[x] = 1;
  }
  for (int i = 1; i <= m; ++i) {
    int x;
    cin >> x;
    has2[x] = 1;
  }
  int mn = 9, mn2 = 9;
  for (int i = 1; i <= 9; ++i) {
    if (has1[i] && has2[i]) {
      cout << i;
      return 0;
    }
    if (has1[i] && i < mn) mn = i;
    if (has2[i] && i < mn2) mn2 = i;
  }
  cout << min(mn, mn2) << max(mn, mn2);
  return 0;
}
