#include <bits/stdc++.h>
using namespace std;
char s1[5050], s2[5050], ans[5050];
int cnt[30], cnt2[30];
inline int pd(char s1[], char s2[], int cnt[]) {
  int len = strlen(s1), len2 = strlen(s2);
  for (int i = 0; i < len; i++) {
    if (i >= len2) return 1;
    for (int j = 25; j > s2[i] - 'a'; j--) {
      if (cnt[j]) return 1;
    }
    if (cnt[s2[i] - 'a'])
      cnt[s2[i] - 'a']--;
    else
      return 0;
  }
  if (len <= len2) return 0;
  return 1;
}
int main(void) {
  scanf("%s%s", s1, s2);
  int len = strlen(s1), len2 = strlen(s2);
  for (int i = 0; i < len; i++) cnt[s1[i] - 'a']++;
  for (int i = 0; i < 26; i++) cnt2[i] = cnt[i];
  if (!pd(s1, s2, cnt2)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < len; i++) {
    int j = s2[i] - 'a', flag = 0;
    if (i < len2) {
      if (cnt[j]) {
        for (int k = 0; k < 26; k++) cnt2[k] = cnt[k];
        cnt2[j]--;
        if (pd(s1 + i + 1, s2 + i + 1, cnt2)) {
          cnt[j]--;
          ans[i] = 'a' + j;
          flag = 1;
        }
      }
    }
    if (!flag) {
      if (i >= len2)
        j = 0;
      else
        j++;
      for (; j < 26; j++) {
        if (cnt[j]) {
          cnt[j]--;
          ans[i] = 'a' + j;
          for (int p = 0; p < 26; p++)
            for (int q = 1; q <= cnt[p]; q++) ans[++i] = 'a' + p;
          break;
        }
      }
      break;
    }
  }
  ans[len] = 0;
  cout << ans << endl;
  return 0;
}
