#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[15], b[15];
int main() {
  int n, m, x = INF, y = INF;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x = min(x, a[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    y = min(y, b[i]);
  }
  if (x == y)
    cout << x << endl;
  else {
    int p = min(x, y), q = max(x, y);
    if (p == 0)
      cout << q << p << endl;
    else
      cout << p << q << endl;
  }
  return 0;
}
