Example

Input

3
y 7
y 6
n 5


Output

1
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

typedef double ld;
const ld eps = 1e-8;

char d[1000];
int a[1000];

int tmp = 0;
bool chked[1000][1000];
int ids[1000][1000];

bool used[3000][1001];
int memo[3000][1001];

int noma[1000][1000];
int chk[1000][1000];
int yemi[1000][1000];

int dfs(int l, int r,int x) {
	if (l > r)return 0;
	if (!chked[l][r]) {
		ids[l][r] = tmp; tmp++;
		chked[l][r] = true;
	}
	int id = ids[l][r];
	if (used[id][x])return memo[id][x];
	used[id][x] = true;
	int res;
	if (noma[l][r] < 0) {
		if (x < yemi[l][r]) {
			res= 0;
		}
		else {
			res= 1;
		}
	}
	else {
		int mid = chk[l][r];
		int vl = dfs(l, mid - 1, x) + dfs(mid + 1, r, x);
		int vr = 1 + dfs(l, mid - 1, noma[l][r]) + dfs(mid + 1, r, noma[l][r]);
		res = min(vl, vr);
	}
	return memo[id][x] = res;
}

void solve() {
	int n; cin >> n;
	rep(i, n) {
		cin >> d[i] >> a[i];
	}
	rep(i, n) {
		int ma = -1;
		int mi = mod; int id = -1;
		Rep(j, i, n) {
			if (d[j] == 'n') {
				if (ma < a[j]) {
					ma = a[j]; id = j;
				}
			}
			else {
				mi = min(mi, a[j]);
			}
			noma[i][j] = ma;
			chk[i][j] = id;
			yemi[i][j] = mi;
		}
	}
	cout << dfs(0, n-1, 1000) << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(1);
	solve();
	//stop
		return 0;
}

