# -*- coding: utf-8 -*- """ No.204 ゴールデン・ウィーク(2) https://yukicoder.me/problems/no/204 """ import sys from sys import stdin input = stdin.readline def check_streak(gw, s, D): tmp = gw[:] for i in range(s, s+D): if s+D >= len(gw): break tmp[i] = 'o' ans = 0 day = 0 for d in tmp: if d == 'o': day += 1 else: ans = max(ans, day) day = 0 ans = max(ans, day) return ans def main(args): D = int(input()) gw = list(input().strip()) gw.extend(list(input().strip())) longest_gw = 0 for s in range(14): day_off = check_streak(gw, s, D) longest_gw = max(longest_gw, day_off) print(longest_gw) if __name__ == '__main__': main(sys.argv[1:])