#include <bits/stdc++.h>
using namespace std;
char a[2000000];
char s[2000000];
int w[2000000];
char ans[2000000];
int main() {
  cin >> a;
  {
    int f = 0;
    int flag = 0;
    cin >> s;
    memset(w, 0, sizeof(w));
    for (int i = 0; i < strlen(a); i++) w[a[i]]++;
    for (int i = 0; i < strlen(a); i++) {
      if (i >= strlen(s)) {
        f = 1;
        while (i < strlen(a)) {
          for (int k = 'a'; k <= 'z'; k++)
            if (w[k]) {
              ans[i++] = k, w[k]--;
              break;
            }
        }
        break;
      }
      if (w[s[i]] && i != strlen(a) - 1) {
        w[s[i]]--;
        ans[i] = s[i];
      } else {
        for (int k = s[i] + 1; k <= 'z'; k++) {
          if (w[k]) {
            w[k]--;
            ans[i++] = k;
            flag = 1;
            break;
          }
        }
        if (flag) {
          f = 1;
          while (i < strlen(a)) {
            for (int k = 'a'; k <= 'z'; k++)
              if (w[k]) {
                ans[i++] = k, w[k]--;
                break;
              }
          }
          break;
        } else {
          for (i = i - 1; i >= 0; i--) {
            w[ans[i]]++;
            for (int k = s[i] + 1; k <= 'z'; k++)
              if (w[k]) {
                w[k]--;
                ans[i++] = k;
                flag = 1;
                break;
              }
            if (flag) break;
          }
          if (flag) {
            f = 1;
            while (i < strlen(a)) {
              for (int k = 'a'; k <= 'z'; k++)
                if (w[k]) {
                  ans[i++] = k, w[k]--;
                  break;
                }
            }
            break;
          }
        }
        break;
      }
    }
    if (f)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
