n = int(raw_input()) w = "xxxxxxxxxxxxxxxxxxxxx"+raw_input()+raw_input()+"xxxxxxxxxxxxxxxxxxxxx" sall=[] ball=[] s = 0 b = 0 for e in w: if e=='o': if b>0: ball.append(b) b=0 s+=1 else: if s>0: sall.append(s) s=0 b+=1 sall.append(s) ball.append(b) all=[] for i in xrange(len(sall)-1): all.append(sall[i]+sall[i+1]) anss=[] for i,e in enumerate(ball): if e<=n: anss.append(e+all[i-1]) anss.append(max(sall)+n) print max(anss)