// Arup Guha
// 12/19/2019
// Solution to 2014 April USACO Silver Problem: Fair Photography

import java.util.*;
import java.io.*;

public class fairphoto {

	public static void main(String[] args) throws Exception {
		
		BufferedReader stdin = new BufferedReader(new FileReader("fairphoto.in"));
		int n = Integer.parseInt(stdin.readLine().trim());
		
		// Read in where the cows are.
		cow[] list = new cow[n];
		for (int i=0; i<n; i++) {
			StringTokenizer tok = new StringTokenizer(stdin.readLine());
			int loc = Integer.parseInt(tok.nextToken());
			char c = tok.nextToken().charAt(0);
			list[i] = new cow(loc, c);
		}
		
		// Sort the cows from left to right.
		Arrays.sort(list);
		
		// minIndex[i] will store the minimum index of the cumulative frequency index equals n+i.
		int[] minIndex = new int[2*n];
		Arrays.fill(minIndex, n+1);
		minIndex[n] = 0;
		
		// Cumulative sum array, use to update minIndex also.
		int[] cumSum = new int[n+1];
		for (int i=1; i<=n; i++) {
			cumSum[i] = cumSum[i-1] + list[i-1].val;
			if (minIndex[cumSum[i]+n] == n+1)
				minIndex[cumSum[i]+n] = i;
		}
		
		// Now, adjust minIndex[i] so it stores the min index-1 where cum frequency is <= n+i.
		for (int i=1; i<minIndex.length; i++)
			minIndex[i] = Math.min(minIndex[i], minIndex[i-1]);
			
		// Now, we can just sweep through the cumSum data.
		// For each point, we ask the furthest back we can go to get a net non-negative of white cows.
		int res = 0;
		for (int i=0; i<n; i++) {
			
			// Max range is valid so update.
			if ((i - minIndex[cumSum[i+1]+n])%2 == 1)
				res = Math.max(res, list[i].loc - list[minIndex[cumSum[i+1]+n]].loc);
			
			// If not, see if we can clip off the last cow.
			else if (minIndex[cumSum[i+1]+n]+2 <= n && cumSum[i+1] - cumSum[minIndex[cumSum[i+1]+n]+2] >= 0)
				res = Math.max(res, list[i].loc - list[minIndex[cumSum[i+1]+n]+1].loc);
		}
		
		// Output to file.
		PrintWriter out = new PrintWriter(new FileWriter("fairphoto.out"));
		out.println(res);
		out.close();		
		stdin.close();
	}
	
}

class cow implements Comparable<cow> {

	public int loc;
	public int val;
	
	public cow(int myLoc, char type) {
		loc = myLoc;
		val = type == 'W' ? 1 : -1;
	}
	
	public int compareTo(cow other) {
		return loc - other.loc;
	}
}