from collections import Counter def is_subsequence(s, t): it = iter(t) for c in s: found = False while True: try: curr = next(it) if curr == c: found = True break except StopIteration: break if not found: return False return True s = input().strip() t = input().strip() # Step 1: Check for any character in S not present in T t_chars = set(t) missing_chars = [] for c in s: if c not in t_chars: missing_chars.append(c) if missing_chars: print(min(missing_chars)) exit() # Step 2: Check for characters where count in S exceeds count in T count_s = Counter(s) count_t = Counter(t) for c in 'abcdefghijklmnopqrstuvwxyz': if count_s.get(c, 0) > count_t.get(c, 0): required = count_t[c] + 1 print(c * required) exit() # Step 3: Check if S is a subsequence of T if not is_subsequence(s, t): print(s) else: print(-1)