/**
*    author:  tomo0608
*    created: 18.02.2021 21:47:19
**/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

// Primality test
class Prime {
    public:
    const int N;
    vector<int> min_prime;
    vector<int> primes;
    Prime(int size): N(size), min_prime(N+1){
        rep(i,N+1)min_prime[i] = i;
        min_prime[0] = -1;
        min_prime[1] = -1;
        for(int i = 2;i<=N;i++){
            if(min_prime[i]!=i)continue;
            primes.push_back(i);
            int tmp = 2*i;
            while(tmp <= N){
                if(min_prime[tmp]==tmp)min_prime[tmp] = i;
                tmp += i;
            }
        }
    }
    bool check(int x){ return min_prime[x] == x;}
};

void solve(){
    ll n,x;cin >> n >> x;
    V<ll> a(n);cin >> a;
    map<pll, ll> memo;
    auto dp = [&](auto &&dp, ll now, ll X)->ll{
        if(now == n-1)return 1;
        if(memo.count({now, X}))return memo[{now, X}];
        ll nmax = a[now+1]/a[now];
        memo[{now, X}] = dp(dp, now+1, X/nmax) + (X%nmax != 0)*dp(dp, now+1, X/nmax + 1);
        return memo[{now, X}];
    };
    cout << dp(dp, 0, x) << endl;
    //cout << memo << endl;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << setprecision(20);
    int codeforces = 1;
    //cin >> codeforces;
    while(codeforces--){
        solve();
    }
    return 0;
}
#include <algorithm>
#include <iostream>
#include <limits>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	int numDog = N * 2;

	unordered_map<char, vector<long long>> a;
	a['R'];
	a['B'];
	a['G'];
	for(int i = 0; i < numDog; i++) {
		long long aa;
		char c;
		cin >> aa >> c;
		a[c].push_back(aa);
	}

	// もしどの色も偶数なら0が最小
	bool allEven = true;
	char evenColor;
	for(auto &x : a) {
		if(x.second.size() % 2 == 1) {
			allEven = false;
		} else {
			evenColor = x.first;
		}
	}
	if(allEven) {
		cout << 0 << endl;
		return 0;
	}

	// そうでないなら、必ず偶数、奇数、奇数の組合せ
	// 奇数同士をペアにする場合と、偶数から2匹もらう場合がある

	for(auto &x : a) {
		sort(x.second.begin(), x.second.end());
	}
	
	vector<vector<long long>*> odd;
	vector<long long> *even = nullptr;
	for(auto &x : a) {
		if(x.second.size() % 2 == 0) {
			even = &a[x.first];
		} else {
			odd.push_back(&a[x.first]);
		}
	}

	// 奇数同士
	int i = 0, j = 0;
	long long result = 1e17;
	while(true) {
		if(i >= odd[0]->size() || j >= odd[1]->size()) {
			break;
		}
		auto x = odd[0]->at(i);
		auto y = odd[1]->at(j);
		result = min(result, abs(x - y));
		if(x < y) {
			i++;
		} else {
			j++;
		}
	}

	// 偶数から借りる
	i = j = 0;
	int used;
	long long t1 = 1e17;
	while(true) {
		if(i >= odd[0]->size() || j >= even->size()) {
			break;
		}
		auto x = odd[0]->at(i);
		auto y = even->at(j);
		if(abs(x - y) < t1) {
			used = j;
		}
		t1 = min(t1, abs(x - y));
		if(x < y) {
			i++;
		} else {
			j++;
		}
	}
	i = j = 0;
	long long t2 = 1e17;
	while(true) {
		if(i >= odd[1]->size() || j >= even->size()) {
			break;
		}
		auto x = odd[1]->at(i);
		auto y = even->at(j);
		if(j != used) {
			t2 = min(t2, abs(x - y));
		}
		if(x < y) {
			i++;
		} else {
			j++;
		}
	}

	result = min(result, t1 + t2);

	cout << result << endl;

	return 0;
}
