#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[10];
  int b[10];
  int m, n;
  while (cin >> m >> n) {
    int index;
    index = 1;
    for (int i = 0; i < m; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
      cin >> b[i];
    }
    int x, y;
    sort(a, a + m);
    sort(b, b + n);
    x = a[0];
    y = b[0];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (index == 0) break;
        if (a[j] == b[j]) {
          cout << a[j] << endl;
          index = 0;
        }
      }
    }
    if (index) {
      if (x == y)
        cout << x << endl;
      else if (x > y)
        cout << y * 10 + x << endl;
      else
        cout << x * 10 + y << endl;
    }
  }
  return 0;
}
