#include <bits/stdc++.h>
using namespace std;
char sa[10010], sb[10010], res[10010];
int cnt[30];
int main() {
  while (~scanf("%s%s", sa, sb)) {
    int ff = 0;
    int la = strlen(sa), lb = strlen(sb);
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; sa[i]; i++) cnt[sa[i] - 'a']++;
    int cc = 0, sg = 0, p;
    for (int i = 0; sb[i];) {
      if (cnt[sb[i] - 'a']) {
        res[i] = sb[i];
        p = i;
        cnt[sb[i] - 'a']--;
        if (la == lb && p == la - 1) {
          int gg = 0;
          for (int k = i; k >= 0; k--) {
            cnt[res[k] - 'a']++;
            int fd = -1;
            for (int j = res[k] - 'a' + 1; j < 26; j++) {
              if (cnt[j]) {
                fd = j;
                break;
              }
            }
            if (fd != -1) {
              res[k] = fd + 'a';
              p = k;
              cnt[fd]--;
              i = k + 1;
              gg = 1;
              break;
            }
          }
          if (!gg) {
            ff = 1;
          }
          break;
        }
        if (p == la - 1) break;
        if (p == lb - 1) break;
        i++;
      } else {
        int pg = -1;
        for (int j = sb[i] - 'a'; j < 26; j++) {
          if (cnt[j]) {
            pg = j;
            break;
          }
        }
        if (pg == -1) {
          int gg = 0;
          for (int k = i - 1; k >= 0; k--) {
            cnt[res[k] - 'a']++;
            int fd = -1;
            for (int j = res[k] - 'a' + 1; j < 26; j++) {
              if (cnt[j]) {
                fd = j;
                break;
              }
            }
            if (fd != -1) {
              res[k] = fd + 'a';
              p = k;
              cnt[fd]--;
              i = k + 1;
              gg = 1;
              break;
            }
          }
          if (!gg) {
            ff = 1;
          }
          break;
        } else {
          res[i] = pg + 'a';
          p = i;
          break;
        }
      }
    }
    if (ff) {
      printf("-1\n");
      continue;
    }
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; sa[i]; i++) cnt[sa[i] - 'a']++;
    p++;
    for (int i = 0; i < p; i++) cnt[res[i] - 'a']--;
    for (int i = 0; i < 26; i++)
      while (cnt[i]--) res[p++] = i + 'a';
    res[p] = 0;
    if (strcmp(res, sb) > 0)
      printf("%s\n", res);
    else
      puts("-1");
  }
  return 0;
}
