D = int(input()) s = input().strip() + input().strip() segments = [] if s: current_type = s[0] current_length = 1 for c in s[1:]: if c == current_type: current_length += 1 else: segments.append((current_type, current_length)) current_type = c current_length = 1 segments.append((current_type, current_length)) max_d = 0 for typ, length in segments: if typ == 'o' and length > max_d: max_d = length if D == 0: print(max_d) exit() max_a = D if segments and segments[0][0] == 'o': max_a = D + segments[0][1] max_b = D if segments and segments[-1][0] == 'o': max_b = segments[-1][1] + D max_c = 0 for i in range(len(segments)): typ, length = segments[i] if typ == 'x': prev_o = segments[i-1][1] if i > 0 and segments[i-1][0] == 'o' else 0 next_o = segments[i+1][1] if i < len(segments)-1 and segments[i+1][0] == 'o' else 0 current = prev_o + min(length, D) + next_o if current > max_c: max_c = current result = max(max_a, max_b, max_c, max_d) print(result)