// Java version of tgr's cpp solution by font // (my autojudge script is Java only) import java.util.*; import java.io.*; public class unb_tgr_port { public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter(System.out); new unb_tgr_port(new FastScanner(System.in), out); out.close(); } public unb_tgr_port(FastScanner in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); String s = in.next(); int[] c = new int[n]; int basevalue = 0; StringBuilder sb = new StringBuilder(); for (int i=0; i> 1; int rightfix = (1+finaldep-mindep) >> 1; int fixcost = leftfix + rightfix; if (fixcost > k || n%2 == 1) { out.println(-basevalue); return; } int MAXCOST = 1200; int[] counts = new int[MAXCOST]; int avail = 0; for (int i=0; i> 1; rightfix = (1+finaldep-dep) >> 1; if (avail + leftfix + rightfix > k) { int totcost = 0; int need = k - leftfix - rightfix + 1; for (int ci=0; need > 0; ci++) { if (counts[ci] > 0) { if (counts[ci] >= need) { totcost += ci * need; break; } else { totcost += ci * counts[ci]; need -= counts[ci]; } } } bestsol = Math.min(bestsol, totcost); } if (i < n) { if (s.charAt(i) == ')') { dep--; counts[c[i]]--; avail--; } else { dep++; counts[c[i]]++; avail++; } } } if (bestsol == Integer.MAX_VALUE) out.println("?"); else out.println(bestsol - basevalue); } } class FastScanner{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; } int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars){ curChar = 0; try{ numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } boolean isSpaceChar(int c) { return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; } boolean isEndline(int c) { return c=='\n'||c=='\r'||c==-1; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String next(){ int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do{ res.appendCodePoint(c); c = read(); }while(!isSpaceChar(c)); return res.toString(); } String nextLine(){ int c = read(); while (isEndline(c)) c = read(); StringBuilder res = new StringBuilder(); do{ res.appendCodePoint(c); c = read(); }while(!isEndline(c)); return res.toString(); } }