use std::io::{self, BufRead}; fn get_lines() -> Vec { let stdin = io::stdin(); let lines: Vec = stdin.lock().lines().map(|l| l.unwrap()).collect(); return lines; } fn main(){ let l = get_lines(); let x: Vec = l[0].split(' ').map(|x| x.parse::().unwrap()).collect(); let (n, k) = (x[0], x[1]); let s = &l[1]; let mut i = k; let mut r = 1; if n / 2 >= k { let mut x = s.chars(); if x.nth((k - 1) as usize).unwrap() == '(' { for c in x { i += 1; r += if c == '(' { 1 } else { -1 }; if r == 0 { println!("{}", i); return; } } } else { for c in s.chars().rev().skip((n - (k - 1)) as usize) { i -= 1; r += if c == ')' { 1 } else { -1 }; if r == 0 { println!("{}", i); return; } } } } else { let mut x = s.chars().rev(); if x.nth((n - k) as usize).unwrap() == ')' { for c in x { i -= 1; r += if c == ')' { 1 } else { -1 }; if r == 0 { println!("{}", i); return; } } } else { for c in s.chars().skip(k as usize) { i += 1; r += if c == '(' { 1 } else { -1 }; if r == 0 { println!("{}", i); return; } } } } }