Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner.

Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep up with the neighbours, they decided to call the baby so that the name was lexicographically strictly larger than the neighbour's son's name t.

On the other hand, they suspect that a name tax will be introduced shortly. According to it, the Taucetians with lexicographically larger names will pay larger taxes. That's the reason abac and bbad want to call the newborn so that the name was lexicographically strictly larger than name t and lexicographically minimum at that.

The lexicographical order of strings is the order we are all used to, the "dictionary" order. Such comparison is used in all modern programming languages to compare strings. Formally, a string p of length n is lexicographically less than string q of length m, if one of the two statements is correct:

  * n < m, and p is the beginning (prefix) of string q (for example, "aba" is less than string "abaa"), 
  * p1 = q1, p2 = q2, ..., pk - 1 = qk - 1, pk < qk for some k (1 ≤ k ≤ min(n, m)), here characters in strings are numbered starting from 1. 



Write a program that, given string s and the heighbours' child's name t determines the string that is the result of permutation of letters in s. The string should be lexicographically strictly more than t and also, lexicographically minimum.

Input

The first line contains a non-empty string s (1 ≤ |s| ≤ 5000), where |s| is its length. The second line contains a non-empty string t (1 ≤ |t| ≤ 5000), where |t| is its length. Both strings consist of lowercase Latin letters.

Output

Print the sought name or -1 if it doesn't exist.

Examples

Input

aad
aac


Output

aad


Input

abad
bob


Output

daab


Input

abc
defg


Output

-1


Input

czaaab
abcdef


Output

abczaa

Note

In the first sample the given string s is the sought one, consequently, we do not need to change the letter order there.
// package ALLD;

import java.io.*;
import java.util.*;

public class CF180D {
    static FastReader s;
    static PrintWriter out;
    static String INPUT = "ac\n" +
            "c";

    public static void main(String[] args) {
        long time = System.currentTimeMillis();
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        out = new PrintWriter(System.out);
        s = new FastReader(oj);

        String str1 = s.next();
        String str2 = s.next();
        TreeMap<Character, Integer> map1 = new TreeMap<>();

        for (int i = 0; i < str1.length(); i++) {
            map1.put(str1.charAt(i), map1.getOrDefault(str1.charAt(i),0) + 1);
        }

        String s1 = func(str1, str2, map1, 0);
        out.println(s1 == null ? -1 : s1);

        if (!oj) {
            System.out.println(Arrays.deepToString(new Object[]{System.currentTimeMillis() - time + " ms"}));
        }
        out.flush();
    }

    private static String func(String str1, String str2, TreeMap<Character, Integer> map, int start) {
        if(str1.length() == start) {
            return null;
        }
        if(start == str2.length()) {
            if(start < str1.length()) {
                ArrayList<Character> list = new ArrayList<>(map.keySet());
                StringBuilder str = new StringBuilder();
                boolean bool = false;
                for (int i = 0; i < list.size(); i++) {
                    char ch = list.get(i);
                    int freq = map.get(ch);
                    for (int j = 0; j < freq; j++) {
                        str.append(ch);
                    }
                    bool = true;
                }
//                char next = map.higherKey(ch1);
//                map.put(next, num );
//                if(bool) {
                    char[] arr = str.toString().toCharArray();
                    Arrays.sort(arr);
                    return new String(arr);
//                } else {
//                    return "";
//                }
//                

            }

        }
        char ch1 = str2.charAt(start);

        if(map.containsKey(ch1)) {
            int num = map.get(ch1);
            if(num == 1) {
                map.remove(ch1);
            } else {
                map.put(ch1, num - 1);
            }

            String ans = func(str1, str2, map, start + 1);
            if(ans == null) {
                map.put(ch1, map.getOrDefault(ch1,0) + 1);
                if(map.higherKey(ch1) == null) {
                    return null;
                } else {
                    char next = map.higherKey(ch1);
                    num = map.get(next);
                    if(num == 1) {
                        map.remove(next);
                    } else {
                        map.put(next, num - 1);
                    }
                    ArrayList<Character> list = new ArrayList<>(map.keySet());
                    StringBuilder str = new StringBuilder();
                    boolean bool = false;
                    for (int i = 0; i < list.size(); i++) {
                        char ch = list.get(i);
                        int freq = map.get(ch);
                        for (int j = 0; j < freq; j++) {
                            str.append(ch);
                        }
                        bool = true;
                    }

                    map.put(next, num );
                    if(bool) {
                        char[] arr = str.toString().toCharArray();
                        Arrays.sort(arr);
                        return next + new String(arr);
                    } else {
                        return next+"";
                    }
                }
            } else {
                return ch1 + ans;
            }
        } else {
            if (map.higherKey(ch1) == null) {
                return null;
            } else {
                char next = map.higherKey(ch1);
                int num = map.get(next);
                if (num == 1) {
                    map.remove(next);
                } else {
                    map.put(next, num - 1);
                }
                ArrayList<Character> list = new ArrayList<>(map.keySet());
                StringBuilder str = new StringBuilder();
                boolean bool = false;
                for (int i = 0; i < list.size(); i++) {
                    char ch = list.get(i);
                    int freq = map.get(ch);
                    for (int j = 0; j < freq; j++) {
                        str.append(ch);
                    }
                    bool = true;
                }

                map.put(next, num);
                if(bool) {
                    char[] arr = str.toString().toCharArray();
                    Arrays.sort(arr);
                    return next + new String(arr);
                } else {
                    return next+"";
                }
            }
        }
    }

    private static class FastReader {
        InputStream is;

        public FastReader(boolean onlineJudge) {
            is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        }

        byte[] inbuf = new byte[1024];
        public int lenbuf = 0, ptrbuf = 0;

        int readByte() {
            if (lenbuf == -1)
                throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }

        boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b))
                ;
            return b;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char) skip();
        }

        String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        String nextLine() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        char[][] nextMatrix(int n, int m) {
            char[][] map = new char[n][];
            for (int i = 0; i < n; i++)
                map[i] = next(m);
            return map;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        int[][] next2DInt(int n, int m) {
            int[][] arr = new int[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArray(m);
            }
            return arr;
        }

        long[][] next2DLong(int n, int m) {
            long[][] arr = new long[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLongArray(m);
            }
            return arr;
        }

        int[] shuffle(int[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                arr[i] = arr[i] ^ arr[j];
                arr[j] = arr[i] ^ arr[j];
                arr[i] = arr[i] ^ arr[j];
            }
            return arr;
        }

        int[] uniq(int[] arr) {
            Arrays.sort(arr);
            int[] rv = new int[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }
    }
}
