#include <bits/stdc++.h>
int my[128] = {0};
char a[5005] = {0}, b[5005] = {0};
char str[5005] = {0};
bool tt(int x) {
  int k = 0;
  for (k = 'z'; k > b[x]; k--) {
    if (my[k] > 0) {
      return true;
    }
  }
  if (my[b[x]] > 0) {
    my[b[x]]--;
    bool ans = tt(x + 1);
    my[b[x]]++;
    return ans;
  }
  return false;
}
int main() {
  int i = 0, j = 0;
  while (scanf("%s%s", a, b) == 2) {
    memset(my, 0, sizeof(my));
    for (i = 0; a[i]; i++) {
      my[a[i]]++;
    }
    if (!tt(0)) {
      printf("%d\n", -1);
      continue;
    }
    for (i = 0;; i++) {
      if (my[b[i]] > 0) {
        my[b[i]]--;
        if (tt(i + 1)) {
          str[i] = b[i];
        } else {
          my[b[i]]++;
          break;
        }
      } else {
        break;
      }
    }
    for (j = b[i] + 1; j <= 'z'; j++) {
      if (my[j] > 0) {
        break;
      }
    }
    my[j]--;
    str[i] = j;
    for (j = 'a'; j <= 'z'; j++) {
      while (my[j] > 0) {
        str[++i] = j;
        my[j]--;
      }
    }
    str[++i] = '\0';
    printf("%s\n", str);
  }
  return 0;
}
