import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int D = scan.nextInt(); String C1 = scan.next(); String C2 = scan.next(); scan.close(); char []c = new char[14]; for(int i = 0; i < 7; i++) { c[i] = C1.charAt(i); } for(int i = 0; i < 7; i++) { c[i + 7] = C2.charAt(i); } int max = 0; for(int i = 0; i < 14; i++) { char []b = new char[14]; for(int j = 0; j < 14; j++) { b[j] = c[j]; } for(int j = i; j < i + D; j++) { if(j > 13) { break; } if(c[j] == 'x') { b[j] = 'o'; }else { break; } } max = Math.max(max, solve(b)); } int cnt1 = 0; for(int i = 0; i < 14; i++) { if(c[i] == 'o') { cnt1 ++; }else { break; } } int cnt2 = 0; for(int i = 13; i >= 0; i--) { if(c[i] == 'o') { cnt2++; }else { break; } } max = Math.max(max, cnt1 + D); max = Math.max(max, cnt2 + D); int cnt3 = 0; for(int i = 0; i < 14; i++) { if(c[i] == 'x') { cnt3 ++; }else { break; } } int cnt4 = 0; for(int i = 0; i < 14; i++) { if(c[i] == 'x') { cnt4 ++; }else { break; } } if(cnt3 <= D) { int cnt5 = 0; for(int i = cnt3; i < 14; i++) { if(c[i] == 'o') { cnt5++; }else { break; } } max = Math.max(max, D + cnt5); } if(cnt4 <= D) { int cnt6 = 0; for(int i = 13 - cnt4; i >= 0; i--) { if(c[i] == 'o') { cnt6++; }else { break; } } max = Math.max(max, D + cnt6); } System.out.println(max); } static int solve(char []c) { int k = 0; int max = 0; for(int i = 0; i < 14; i++) { if(c[i] == 'o') { k++; }else { k = 0; } if(max < k) { max = k; } } return max; } }