import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } enum INF = 10^^9; enum K = 20; void main() { /* debug {{ enum lim = 20; foreach (n; 1 .. lim + 1) { DList!int que; auto dist = new int[1 << n]; dist[] = -1; foreach (u; 0 .. 1 << n) { bool ok = true; int now; foreach (i; 0 .. n) { (u >> i & 1) ? --now : ++now; ok = ok && (now >= 0); } if (ok) { dist[u] = 0; que ~= u; } } for (; !que.empty; ) { const u = que.front; que.removeFront; foreach (i; 0 .. n + 1) foreach (j; i + 1 .. n + 1) { const v = u ^ ((1 << j) - (1 << i)); if (!~dist[v]) { dist[v] = dist[u] + 1; que ~= v; } } } foreach (u; 0 .. 1 << n) if (dist[u] >= 2) { const s = iota(n).map!(i => "+-"[u >> i & 1]).array; writeln(dist[u], " ", s); assert(dist[u] <= 2); } } }} //*/ try { for (; ; ) { const N = readInt; auto S = readToken; auto dp = new int[2 * K + 1][N + 1]; foreach (i; 0 .. N + 1) { static foreach (s; 0 .. 2 * K + 1) { dp[i][s] = -INF; } } dp[0][0] = 0; foreach (i; 0 .. N + 1) { static foreach (s; 0 .. 2 * K + 1) { if (dp[i][s] < 0) { dp[i][s] = -INF; } } static foreach (s; 0 .. 2 * K) { chmax(dp[i][s + 1], dp[i][s]); } if (i < N) { if (S[i] == '?' || S[i] == '+') { static foreach (s; 0 .. 2 * K + 1) { chmax(dp[i + 1][s], dp[i][s] + (-1)^^s); } } if (S[i] == '?' || S[i] == '-') { static foreach (s; 0 .. 2 * K + 1) { chmax(dp[i + 1][s], dp[i][s] - (-1)^^s); } } } } int ans = K + 1; static foreach (k; 0 .. K + 1) { if (dp[N][2 * k] >= 0) { chmin(ans, k); } } writeln(ans); } } catch (EOFException e) { } }