D = int(input()) C = input().strip() + input().strip() S = 'x' * D + C + 'x' * D n = len(S) max_x = [0] * n current = 0 for i in reversed(range(n)): if S[i] == 'x': current += 1 else: current = 0 max_x[i] = current max_length = 0 for i in range(n): possible_k = min(max_x[i], D) if possible_k == 0: continue for k in range(1, possible_k + 1): modified = list(S) for j in range(i, i + k): modified[j] = 'o' current_len = 0 current_max = 0 for c in modified: if c == 'o': current_len += 1 if current_len > current_max: current_max = current_len else: current_len = 0 if current_max > max_length: max_length = current_max print(max_length)