#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 113;
const long long maxn = 1e5 + 113;
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> a1, a2;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    a1.push_back(a);
  }
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    a2.push_back(a);
  }
  for (int i = 1; i <= 99; i++) {
    if (i >= 10) {
      int s1 = i / 10;
      int s2 = i % 10;
      bool tr1 = false, tr2 = false;
      for (int j = 0; j < a1.size(); j++) {
        if (a1[j] == s1) tr1 = true;
        if (a1[j] == s2) tr1 = true;
      }
      for (int j = 0; j < a2.size(); j++) {
        if (a2[j] == s1) tr2 = true;
        if (a2[j] == s2) tr2 = true;
      }
      if (tr1 && tr2) {
        cout << i;
        return 0;
      }
    } else {
      int s2 = i % 10;
      bool tr1 = false, tr2 = false;
      for (int j = 0; j < a1.size(); j++) {
        if (a1[j] == s2) tr1 = true;
      }
      for (int j = 0; j < a2.size(); j++) {
        if (a2[j] == s2) tr2 = true;
      }
      if (tr1 && tr2) {
        cout << i;
        return 0;
      }
    }
  }
}
