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 i == 0 or S[i - 1] == "x": y.append(cntX) cntX = 0 cntO += 1 if cntO > 0: x.append(cntO) y.append(cntX) #print(x, y) if len(x) == 0: print(D) exit() 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)