def find_min_subsequence(S, T): # Step 1: Check if any character in S is not present in T t_set = set(T) candidates = [] for c in S: if c not in t_set: candidates.append(c) if candidates: return min(candidates) # Step 2: Check if S is a subsequence of T def is_subsequence(s, t): i = j = 0 len_s = len(s) len_t = len(t) while i < len_s and j < len_t: if s[i] == t[j]: i += 1 j += 1 else: j += 1 return i == len_s if is_subsequence(S, T): return -1 # Step 3: Binary search to find the minimal k low = 1 high = len(S) answer = None while low <= high: mid = (low + high) // 2 prefix = S[:mid] if is_subsequence(prefix, T): low = mid + 1 else: answer = prefix high = mid - 1 return answer # Read input S = input().strip() T = input().strip() result = find_min_subsequence(S, T) print(result if result is not None else -1)