#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

struct custom_hash {
    static uint64_t splitmix64( uint64_t x ) {
        x += 0x9e3779b97f4a7c15;
        x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9;
        x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb;
        return x ^ ( x >> 31 );
    }

    size_t operator() ( uint64_t x ) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64( x + FIXED_RANDOM );
    }
};

int n;
string str;
pair< ll, ll > a[ 200010 ];
int cnt[ 3 ];

ll get( int, int );
ll getAns( int, int );

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	cin >> n;
	n <<= 1;
	for( int i = 1; i <= n; ++i ) {
		cin >> a[ i ].first >> str;
		if( str[ 0 ] == 'R' )
			a[ i ].second = 0;
		else if( str[ 0 ] == 'G' )
			a[ i ].second = 1;
		else
			a[ i ].second = 2;
		++cnt[ a[ i ].second ];
	}
	if( cnt[ 0 ] % 2 == 0 && cnt[ 1 ] % 2 == 0 && cnt[ 2 ] % 2 == 0 ) {
		cout << 0;
		return 0;
	}
	sort( a + 1, a + 1 + n );
	if( cnt[ 0 ] % 2 == 0 )
		cout << getAns( 1, 2 );
	else if( cnt[ 1 ] % 2 == 0 )
		cout << getAns( 0, 2 );
	else
		cout << getAns( 0, 1 );
	return 0;
}

ll get( int x, int y ) {
	ll ans = MAX_INF_VAL_LL;
	ll lst = -MAX_INF_VAL_LL;
	for( int i = 1; i <= n; ++i ) {
		if( a[ i ].second == y )
			ans = min( ans, a[ i ].first - lst );
		else if( a[ i ].second == x )
			lst = a[ i ].first;
	}
	return ans;
}

ll getAns( int x, int y ) {
	int z = 3 ^ x ^ y;
	ll ans = min( get( x, y ), get( y, x ) );
	if( cnt[ z ] ) {
		ll t1 = min( get( x, z ), get( z, x ) );
		ll t2 = min( get( y, z ), get( z, y ) );
		ans = min( ans, t1 + t2 );
	}
	return ans;
}

/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

void solve() {
    cini(x);
    x%=100;
    cout<<100-x<<endl;
}

signed main() {
    solve();
}