D = input() cal = ['x'] * D + list(raw_input()) + list(raw_input()) + ['x'] * D ans = 0 for i in range(len(cal)-D): #print i #print cal calnow = cal[:i] + ['o'] * D + cal[i+D:] maxnow = max([len(item) for item in ''.join(calnow).split('x')]) ans = max(ans, maxnow) print ans