import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int d = sc.nextInt(); ArrayList cal = new ArrayList<>(); char prev = 'x'; int count = 20; for (char c : (sc.next() + sc.next()).toCharArray()) { if (prev == c) { count++; } else { cal.add(count); count = 1; prev = c; } } if (prev == 'x') { cal.add(count + 20); } else { cal.add(count); cal.add(20); } if (cal.size() == 1) { System.out.println(d); return; } int max = d; for (int i = 0; i < cal.size(); i += 2) { if (i > 0 && i < cal.size() - 1) { if (d >= cal.get(i)) { max = Math.max(max, cal.get(i - 1) + cal.get(i) + cal.get(i + 1)); } else { max = Math.max(max, cal.get(i - 1) + d); max = Math.max(max, cal.get(i + 1) + d); } } else if (i == 0) { max = Math.max(max, cal.get(1) + d); } else { max = Math.max(max, cal.get(cal.size() - 2) + d); } } System.out.println(max); } }