#include <bits/stdc++.h>
using namespace std;
int main() {
  char A[10], B[10];
  int C[10] = {0}, D[10] = {0};
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    cin >> A[i];
    C[i] = (int)A[i] - 48;
  }
  for (int j = 0; j < b; j++) {
    cin >> B[j];
    D[j] = (int)B[j] - 48;
  }
  sort(&C[0], &C[a]);
  sort(&D[0], &D[b]);
  if (C[0] == D[0])
    cout << C[0] << endl;
  else {
    if (C[0] > D[0]) cout << D[0] << C[0] << endl;
    if (C[0] < D[0]) cout << C[0] << D[0] << endl;
  }
  return 0;
}
