// Arup Guha
// 12/23/2019
// Solution to 2014 January USACO Silver Problem: Bessie Slows Down

import java.util.*;
import java.io.*;

public class slowdown {

    public static void main(String[] args) throws Exception {

        Scanner stdin = new Scanner(new File("slowdown.in"));
        int n = stdin.nextInt();

		// Just store these separately.
		ArrayList<Integer> timeList = new ArrayList<Integer>();
		ArrayList<Integer> xList = new ArrayList<Integer>();
		
		// Read in events.
		for (int i=0; i<n; i++) {
			char type = stdin.next().charAt(0);
			int val = stdin.nextInt();
			
			if (type == 'T') timeList.add(val);
			else             xList.add(val);
		}
		
		// Add a dummy events at exactly at the end of the race and way after...
		// Then sort both lists.
		xList.add(1000);
		timeList.add(1000000000);
		Collections.sort(timeList);
		Collections.sort(xList);
		int stopIdx = xList.indexOf(1000);
		
		// At the beginning of the race.
		int tIdx = 0, xIdx = 0, curDiv = 1, res = -1;
		double curT = 0, curD = 0;
		
		// Go through each event.
		while (xIdx <= stopIdx) {
			
			// Figure out what distance the next time stop would occur.
			double deltaT = timeList.get(tIdx) - curT;
			double newD = curD + deltaT/curDiv;
			
			// The time stop is strictly before the distance stop)
			if (newD < xList.get(xIdx)-1e-9) {
				curD = newD;
				curT = timeList.get(tIdx);
				tIdx++;
				curDiv++;
			}
			
			// Distance stop is strictly first.
			else if (xList.get(xIdx) < newD-1e-9) {
				curT = curT + (xList.get(xIdx)-curD)*curDiv;
				curD = xList.get(xIdx);
				xIdx++;
				curDiv++;
			}
			
			// Both trigger 
			else {
				curD = newD;
				curT = timeList.get(tIdx);
				tIdx++;
				xIdx++;
				curDiv+=2;				
			}
					
			// We finished.
			if (Math.abs(1000-curD) < 1e-9) {
				res = (int)(curT+.5);
				break;
			}
		}
        
        // Output the result.
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("slowdown.out")));
        out.println(res);
        out.close();
        stdin.close();
    }
}

