d = int(input()) C = "o" + "x" * (d + 1) + input() + input() + "x" * (d + 1) + "o" bef = "o" lst = [] cnt = 0 for c in C: if c != bef: lst.append(cnt) cnt = 1 bef = c else: cnt += 1 lst.append(cnt) l = len(lst) ans = 0 for i in range(1, l, 2): if lst[i] <= d: ans = max(ans, lst[i - 1] + lst[i] + lst[i + 1]) else: ans = max(ans, max(lst[i - 1], lst[i + 1]) + d) print(ans)