#include<bits/stdc++.h>

using namespace std;

using ll = long long;

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repn(i,n)  rep(i,0,n)

const double EPS = 1e-5;
const int MOD = 1e9+7;
const int INF = INT_MAX / 2;
//for(auto &h : H){ cout << h << " ";} cout << endl;

int main(){
  int r1,c1,r2,c2;
  cin >> r1 >> c1;
  cin >> r2 >> c2;

  int ans = 3;
  if(r1==r2&&c1==c2) ans = 0;
  else if(r1+c1==r2+c2 || r1-c1==r2-c2 || abs(r1-r2)+abs(c1-c2)<=3) ans = 1;
  else if((r1-r2)%2==(c1-c2)%2) ans=2;
  else{
    for(int i=-2;i<=2;i++){
      for(int j=-2;j<=2;j++){
        if((r1+i)+(c1+j)==r2+c2 || (r1+i)-(c1+j)==r2-c2 || abs((r1+i)-r2)+abs((c1+j)-c2)<=3){
          ans = 2;
        }
      }
    }
    int i,j;
    i = 3; j = 0;
    if((r1+i)+(c1+j)==r2+c2 || (r1+i)-(c1+j)==r2-c2 || abs((r1+i)-r2)+abs((c1+j)-c2)<=3){
      ans = 2;
    }
    i = 0; j = 3;
    if((r1+i)+(c1+j)==r2+c2 || (r1+i)-(c1+j)==r2-c2 || abs((r1+i)-r2)+abs((c1+j)-c2)<=3){
      ans = 2;
    }
    i = -3; j = 0;
    if((r1+i)+(c1+j)==r2+c2 || (r1+i)-(c1+j)==r2-c2 || abs((r1+i)-r2)+abs((c1+j)-c2)<=3){
      ans = 2;
    }
    i = 0; j = -3;
    if((r1+i)+(c1+j)==r2+c2 || (r1+i)-(c1+j)==r2-c2 || abs((r1+i)-r2)+abs((c1+j)-c2)<=3){
      ans = 2;
    }
  }

  cout << ans << endl;

}

#include <bits/stdc++.h>

using namespace std;

#define flush cout.flush

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);

ll cur = -1;

ll calc(vector<ll> &a, vector<ll> &b) {
    ll res = INF * INF;
    vector<pl> z;
    for (ll i = 0; i < a.size(); ++i) {
        if (a[i] == cur) {
            cur = -1;
            continue;
        }
        z.push_back({a[i], 0});
    }
    for (ll i = 0; i < b.size(); ++i) {
        z.push_back({b[i], 1});
    }
    ll last0 = -1, last1 = -1;
    sort(z.begin(), z.end());
    for (ll i = 0; i < z.size(); ++i) {
        if (z[i].second == 0) {
            if (last1 != -1 && abs(z[i].first - last1) < res) {
                res = min(res, abs(z[i].first - last1));
            }
            last0 = z[i].first;
        } else {
            if (last0 != -1) {
                res = min(res, abs(z[i].first - last0));
            }
            last1 = z[i].first;
        }
    }
    cur = last0;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> r, g, b;

    for (ll i = 0; i < 2 * n; ++i) {
        ll a;
        cin >> a;
        char c;
        cin >> c;
        if (c == 'R')r.push_back(a);
        if (c == 'B')b.push_back(a);
        if (c == 'G')g.push_back(a);
    }
    if (r.size() % 2 == 0 && b.size() % 2 == 0) {
        cout << "0\n";
        return 0;
    }
    ll res;
    if (r.size() % 2 == 0) {
        res = calc(g, b);
        ll tmp = calc(r, g);
        res = min(res, tmp + calc(r, b));
        cur = -1;
        tmp = calc(r, b);
        res = min(res, tmp + calc(r, g));
        cur = -1;
    } else if (b.size() % 2 == 0) {
        res = calc(r, g);
        ll tmp = calc(b, g);
        res = min(res, tmp + calc(b, r));
        cur = -1;
        tmp = calc(b, r);
        res = min(res, tmp + calc(b, g));
        cur = -1;
    } else {
        res = calc(r, b);
        ll tmp = calc(g, r);
        res = min(res, tmp + calc(g, b));
        cur = -1;
        tmp = calc(g, b);
        res = min(res, tmp + calc(g, r));
        cur = -1;
    }
    cout << res << "\n";
    return 0;
}