#include using namespace std; using ll = long long; const ll MOD = 998244353; const int N = 1000100; ll fac[N], invfac[N]; ll modpow(ll a, ll b, ll MOD){ ll ret = 1; while (b > 0){ if(b & 1){ ret *= a; ret %= MOD; } a *= a; a %= MOD; b >>= 1; } return ret; } void init(){ fac[0] = 1; for(int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % MOD; invfac[N - 1] = modpow(fac[N - 1], MOD - 2, MOD); for(int i = N - 2; i >= 0; i--) invfac[i] = invfac[i + 1] * (i + 1) % MOD; } ll nCk(int n, int k){ if(k < 0 || k > n) return 0; else return (fac[n] * invfac[k] % MOD) * invfac[n - k] % MOD; } // ++++-?-?-?-?+------+++++++------------------------ void solve(){ int n; string S; cin >> n >> S; int tot = 0; int ma = 0; int mi = 0; int mic = 0; int cnt = 0; int ans = 0; bool rev = false; for(auto s:S){ if(s == '+'){ tot++; if(tot > ma){ if(rev){ tot += cnt - mic; tot += 2 * (ma - mi); cnt = 0; } ma = tot; cnt = max(0, cnt - 2); rev = false; mic = 0; } } else if(s == '-'){ tot--; if(tot < 0){ if(!rev){ ans++; rev = true; tot -= cnt; mi = tot; mic = cnt; } else if(tot < mi){ int d1 = mi - tot; int d2 = cnt - mic; if(d1 > d2){ mi = tot; mic = cnt; } } } } else{ cnt += 2; if(rev){ tot--; } else{ tot++; } } } cout << ans << endl; } int main(){ solve(); }