#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 += 2 * (cnt - mic); tot += 2 * (ma - mi); } ma = tot; cnt = 0; rev = false; mic = 0; } } else if(s == '-'){ tot--; if(tot < 0){ if(!rev){ ans++; rev = true; mi = tot; mic = 0; } else if(tot < mi){ mi = tot; mic = cnt; } } } else{ cnt++; if(rev){ tot--; } else{ tot++; } } } cout << ans << endl; } int main(){ solve(); }