d = int(input()) C = input() + input() 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) if bef == "x": lst.append(0) 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)