#include <bits/stdc++.h>
using namespace ::std;
char s[5005];
char t[5005];
int n, m;
int s1[155];
int t1[155];
char la[5005];
int main() {
  int i, j, k;
  scanf("%s", &s[1]);
  n = strlen(&s[1]);
  scanf("%s", &t[1]);
  m = strlen(&t[1]);
  for (i = 1; i <= n; i++) s1[s[i]]++;
  for (i = 1; i <= m && i <= n; i++) {
    if (s1[t[i]] != 0)
      s1[t[i]]--, la[i] = t[i];
    else {
      for (j = i; j >= 1; j--) {
        if (j != i) s1[t[j]]++;
        for (k = t[j] + 1; k <= 150; k++) {
          if (s1[k] != 0) {
            la[j] = k;
            s1[k]--;
            for (int l = 1; l <= j; l++) printf("%c", la[l]);
            for (int l = 1; l <= 150; l++)
              for (int l1 = 1; l1 <= s1[l]; l1++) printf("%c", l);
            return 0;
          }
        }
      }
      printf("-1");
      return 0;
    }
  }
  if (n > m) {
    for (int l = 1; l <= m; l++) printf("%c", la[l]);
    for (int l = 1; l <= 150; l++)
      for (int l1 = 1; l1 <= s1[l]; l1++) printf("%c", l);
    return 0;
  }
  for (j = n; j >= 1; j--) {
    s1[t[j]]++;
    for (k = t[j] + 1; k <= 150; k++) {
      if (s1[k] != 0) {
        la[j] = k;
        s1[k]--;
        for (int l = 1; l <= j; l++) printf("%c", la[l]);
        for (int l = 1; l <= 150; l++)
          for (int l1 = 1; l1 <= s1[l]; l1++) printf("%c", l);
        return 0;
      }
    }
  }
  printf("-1");
  return 0;
}
