def main(): import sys S = sys.stdin.readline().strip() T = sys.stdin.readline().strip() # Check if there's any character in S not present in T t_chars = set(T) for c in 'abcdefghijklmnopqrstuvwxyz': if c in S and c not in t_chars: print(c) return # Preprocess T for subsequence checks n_t = len(T) next_pos = [[n_t] * 26 for _ in range(n_t + 1)] for i in range(n_t - 1, -1, -1): for c in range(26): next_pos[i][c] = next_pos[i + 1][c] current_ord = ord(T[i]) - ord('a') next_pos[i][current_ord] = i # Check if S is a subsequence of T current_t = 0 for c in S: c_ord = ord(c) - ord('a') pos = next_pos[current_t][c_ord] if pos >= n_t: print(S) return current_t = pos + 1 # If S is a subsequence of T print(-1) if __name__ == "__main__": main()