#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db long double
#define pii pair<int, int>
#define mkp make_pair
using namespace std;
const int N = 1e6 + 7;
int n;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	cout << 100 - n % 100 << "\n";
    return 0;
}
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long long ll;
#define G getchar()
ll read()
{
	ll x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
//typedef pair<int,int> P;
#define rep(i,l,r) for (int i(l),_##i(r);i<=_##i;i++)
#define per(i,l,r) for (int i(r),_##i(l);i>=_##i;i--)
#define all(x) (x).begin(),(x).end()
#define forall(x,y) for (const int &y: e[x])

int n;
int getid(){
	char s[2];
	scanf("%s",s);
	if (s[0]=='R') return 0;
	if (s[0]=='G') return 1;
	return 2;
}

vector<ll> S[3];

void solve(){
	n=read()<<1;
	rep(i,1,n){
		ll x=read();
		S[getid()].pb(x);
	}
	rep(i,0,2) sort(all(S[i]));
	if (S[0].size()&1^1&&S[1].size()&1^1) return puts("0"),void();
	if (S[0].size()&1^1) swap(S[0],S[2]);
	if (S[1].size()&1^1) swap(S[1],S[2]);
	auto A=S[0],B=S[1];
	ll z=1e18; int p=0;
	for (ll x: A){
		while (p<B.size()&&B[p]<=x) ++p;
		if (p<B.size()) z=min(z,abs(B[p]-x));
		if (p) z=min(z,abs(B[p-1]-x));
	}
	ll a=1e18,b=1e18;
	A=S[0],B=S[2]; p=0;
	for (ll x: A){
		while (p<B.size()&&B[p]<=x) ++p;
		if (p<B.size()) a=min(a,abs(B[p]-x));
		if (p) a=min(a,abs(B[p-1]-x));
	}
	A=S[1],B=S[2]; p=0;
	for (ll x: A){
		while (p<B.size()&&B[p]<=x) ++p;
		if (p<B.size()) b=min(b,abs(B[p]-x));
		if (p) b=min(b,abs(B[p-1]-x));
	}
	z=min(z,a+b);
	printf("%lld\n",z);
}

int main()
{
	for (int T=1;T--;) solve();
	return 0;
}