D = int(input()) S = "x" * D + input().rstrip() + input().rstrip() + "x" * D x, y = [], [] cntX, cntO = 0, 0 for i in range(len(S)): if S[i] == "x": if i != 0 and S[i - 1] == "o": x.append(cntO) cntO = 0 cntX += 1 else: if S[i - 1] == "x": y.append(cntX) cntX = 0 cntO += 1 y.append(cntX) MAX = 0 for i in range(len(y)): if y[i] <= D: if i == 0: MAX = max(MAX, y[i] + x[i]) elif i == len(y) - 1: MAX = max(MAX, x[i - 1] + y[i]) else: MAX = max(MAX, x[i - 1] + y[i] + x[i]) else: if i == 0: MAX = max(MAX, D + x[i]) elif i == len(y) - 1: MAX = max(MAX, x[i - 1] + D) else: MAX = max(MAX, x[i - 1] + D) MAX = max(MAX, D + x[i]) print(MAX)