def min_operations(N, S, T): S_list = list(S) T_list = list(T) operations = 0 for j in range(N): if S_list[j] == T_list[j]: continue # Check if j is at the first or last position, can't have i=j-1 if j == 0 or j == N-1: return -1 # Check if the condition is satisfied if S_list[j-1] != S_list[j+1]: # Try to flip j+1 if possible if j+1 == N-1: return -1 # Check if j+1-1 and j+1+1 are same if S_list[j] != S_list[j+2]: return -1 # Flip j+1 S_list[j+1] = 'A' if S_list[j+1] == 'B' else 'B' operations += 1 # Now check again if condition is satisfied if S_list[j-1] != S_list[j+1]: return -1 # Flip j S_list[j] = 'A' if S_list[j] == 'B' else 'B' operations += 1 return operations # 读取输入 N = int(input()) S = input().strip() T = input().strip() # 处理特殊情况:如果长度不同,直接返回-1(虽然题目保证长度相同) if len(S) != len(T): print(-1) else: # 转换为列表便于处理 S_list = list(S) T_list = list(T) # 检查是否可以转换 ok = True for i in range(N): if S_list[i] != T_list[i]: # 检查是否存在满足条件的位置来处理差异点 if i == 0 or i == N-1: ok = False break if (i == 1 or i == N-2): pass else: pass if not ok: print(-1) else: # 计算操作次数 res = min_operations(N, S, T) print(res if res != -1 else -1)