#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[10005], b[10005], minn1 = 1e9, minn2 = 1e9;
int main() {
  cin >> n >> m;
  if (n == 1) {
    cout << n;
    return 0;
  }
  if (m == 1) {
    cout << m;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    minn1 = min(a[i], minn1);
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    minn2 = min(b[i], minn2);
  }
  if (minn1 < minn2) {
    cout << minn1 << minn2;
    return 0;
  }
  if (minn2 < minn1) {
    cout << minn2 << minn1;
    return 0;
  }
  if (minn1 == minn2) {
    cout << minn1;
    return 0;
  }
}
