D = int(raw_input()) C = ["x" for i in range(14)] + list(raw_input()) + list(raw_input()) count = 0 max_holiday = 0 for i in range(42): if C[i] == "o": count += 1 else: count += D for j in range(i+D,28): if C[j] == "o": count += 1 else: break max_holiday = max(max_holiday, count) count = 0 else: max_holiday = max(max_holiday, count + D) print max_holiday