#!/usr/bin/python3 D = int(input()) C = input() C += input() tar = 'o' cntarray = [] cnt = 0 for i in range(len(C)): if C[i] is tar: cnt = cnt+1 else: cntarray.append(cnt) cnt = 1 tar = 'x' if (tar is 'o') else 'o' cntarray.append(cnt) ma = 0 for i in range(0, len(cntarray)-2, 2): if cntarray[i+1] <= D: ma = max(ma, cntarray[i]+cntarray[i+1]+cntarray[i+2]) else: ma = max(ma, cntarray[i]+D) ma = max(ma, cntarray[i+2]+D) if len(cntarray) % 2 is 0: ma = max(ma, cntarray[-2]+D) else: ma = max(ma,cntarray[-1]+D) if C[0] is 'o': ma = max(ma, cntarray[0]+D) else: ma = max(ma, cntarray[2]+D) print(ma)