#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll>pll;

ll n,x[100010]={0},y[100010]={0};
vector<pll>vx,vy;
vector<pll>edge[100010];
priority_queue<pll,vector<pll>,greater<pll>>q;
//priority_queue<pll>q;
bool used[100010];
ll res=0;

signed main(){

    cin>>n;
    for(int i=0;i<n;++i){
        cin>>x[i]>>y[i];
        vx.push_back(pll(x[i],i));
        vy.push_back(pll(y[i],i));
    }

    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end());
    for(int i=0;i<n-1;++i){
        ll j=vx[i].second,k=vx[i+1].second;
        ll wj=vx[i].first,wk=vx[i+1].first;
        edge[j].push_back(pll(wk-wj,k));
        edge[k].push_back(pll(wk-wj,j));
        j=vy[i].second,k=vy[i+1].second;
        wj=vy[i].first,wk=vy[i+1].first;
        edge[j].push_back(pll(wk-wj,k));
        edge[k].push_back(pll(wk-wj,j));
    }

    for(int i=0;i<n;++i){
        used[i]=false;
    }
    int c=1;
    for(int i=0;i<edge[0].size();++i)q.push(edge[0][i]);
    used[0]=true;
    while(c<n){
        pll t=q.top();
        q.pop();
        if(!used[t.second]){
            res+=t.first;
            for(int i=0;i<edge[t.second].size();++i){
                q.push(edge[t.second][i]);
            }
            used[t.second]=true;
            c++;
            //cout<<t.first<<" "<<t.second<<endl;
        }
    }

    cout<<res<<endl;

    return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string a,b,c;
	cin>>n>>a>>b>>c;
	int ans=0;
	rep(i,n){
		set<char> cnt;
		cnt.insert(a[i]),cnt.insert(b[i]),cnt.insert(c[i]);
		if(cnt.size()==3) ans+=2;
		else if(cnt.size()==2) ans+=1;
	}
	cout<<ans<<endl;
}