#include <bits/stdc++.h>
char s[5009], t[5009], ans[5009];
int cnt[1 << 8];
int main() {
  int i, j, k, l1, l2;
  while (scanf("%s%s", s, t) != EOF) {
    l1 = strlen(s);
    l2 = strlen(t);
    memset(cnt, 0, sizeof(cnt));
    for (i = 0; i < l1; i++) {
      cnt[s[i]]++;
    }
    for (i = 0; i < l2; i++) {
      if (cnt[t[i]] == 0) break;
      ans[i] = t[i];
      cnt[t[i]]--;
    }
    if (i == l2 && l1 > l2) {
      for (j = 0; j < 128; j++) {
        for (k = 0; k < cnt[j]; k++) ans[i++] = j;
      }
      ans[i] = 0;
      puts(ans);
      continue;
    }
    cnt[t[i]]--;
    for (j = i; j >= 0; j--) {
      cnt[t[j]]++;
      for (k = t[j] + 1; k <= 'z'; k++) {
        if (cnt[k]) break;
      }
      if (k <= 'z') {
        ans[j++] = k;
        cnt[k]--;
        for (i = 0; i < 128; i++) {
          for (k = 0; k < cnt[i]; k++) ans[j++] = i;
        }
        ans[j] = 0;
        break;
      }
    }
    puts(j < 0 ? "-1" : ans);
  }
  return 0;
}
