D = int(input()) c1 = input().strip() c2 = input().strip() arr = list(c1 + c2) max_original = 0 current = 0 for c in arr: if c == 'o': current += 1 if current > max_original: max_original = current else: current = 0 if D == 0: print(max_original) exit() max_total = 0 for i in range(0, 14 - D + 1): valid = True for j in range(i, i + D): if j >= 14 or arr[j] != 'x': valid = False break if valid: left = 0 if i > 0: pos = i - 1 while pos >= 0 and arr[pos] == 'o': left += 1 pos -= 1 right = 0 if i + D < 14: pos = i + D while pos < 14 and arr[pos] == 'o': right += 1 pos += 1 total = left + D + right if total > max_total: max_total = total result = max(max_original, max_total) print(result)