#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[10001], b[10001];
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
  }
  for (int i = 1; i <= 99; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= n; ++k) {
        if (i <= 9) {
          if (a[j] == i && b[k] == i) {
            cout << i;
            return 0;
          }
        } else {
          if (i / 10 == min(a[j], b[k]) && i % 10 == max(a[j], b[k])) {
            cout << i;
            return 0;
          }
        }
      }
    }
  }
}
