d = int(input()) a = list(input()) b = list(input()) week = a+b schedule = [] now = 0 for w in week: if w == "o": if now > 0: now += 1 else: schedule.append(now) now = 1 else: if now < 0: now -= 1 else: schedule.append(now) now = -1 schedule.append(now) schedule = schedule[1:] ans = 0 for i,v in enumerate(schedule): if v > 0: continue else: if abs(v) <= d: tmp = abs(v) try: tmp += schedule[i-1] except IndexError: continue try: tmp += schedule[i+1] except IndexError: continue ans = max(ans, tmp) else: tmp = d try: tmp += schedule[i-1] except IndexError: continue ans = max(ans, tmp) tmp = d try: tmp += schedule[i+1] except IndexError: continue ans = max(ans, tmp) if not ans: ans = d if schedule[0] > 0: ans = max(ans, d+schedule[0]) if schedule[-1] > 0: ans = max(ans, d+schedule[-1]) print(ans)