D = int(input()) part1 = input().strip() part2 = input().strip() calendar = part1 + part2 days = [c == 'o' for c in calendar] # Compute left (consecutive o's ending at i) and right (consecutive o's starting at i) n = len(days) left = [0] * n current = 0 for i in range(n): if days[i]: current += 1 else: current = 0 left[i] = current right = [0] * n current = 0 for i in range(n-1, -1, -1): if days[i]: current += 1 else: current = 0 right[i] = current max_original = max(left + right) # Candidate for front application (D days before the input) candidate_front = 0 if days[0]: candidate_front = D + right[0] # Candidate for back application (D days after the input) candidate_back = 0 if days[-1]: candidate_back = left[-1] + D # Find all x-ranges in the input days x_ranges = [] i = 0 while i < n: if not days[i]: start = i while i < n and not days[i]: i += 1 end = i - 1 x_ranges.append((start, end)) else: i += 1 max_x_candidate = 0 for (start, end) in x_ranges: L = end - start + 1 A = 0 if start > 0 and days[start - 1]: A = left[start - 1] B = 0 if end < n - 1 and days[end + 1]: B = right[end + 1] used = min(D, L) current_candidate = A + used + B if current_candidate > max_x_candidate: max_x_candidate = current_candidate max_total = max(max_original, candidate_front, candidate_back, max_x_candidate) print(max_total)