#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int N;
	cin >> N;
    map<string, int> mp;
    rep(i,0,N){
        string s; cin >> s;
        if (s[0] == '!'){
            s = s.substr(1);
            mp[s] |= 1;
        }
        else
            mp[s] |= 2;
    }
    for(auto m:mp){
        if (m.second == 3){
            cout << m.first << endl;
            return 0;
        }
    }
    cout << "satisfiable\n";

}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll L[200200], R[200200];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;

	rep1(i, N) L[i] = 1e12;
	rep1(i, N) R[i] = -1e12;

	rep(i, N) {
		ll x, c;
		cin >> x >> c;
		chmin(L[c], x);
		chmax(R[c], x);
	}

	ll dp0 = 0, dp1 = 0;
	ll za0 = 0, za1 = 0;

	rep1(i, N) {
		if (L[i] > 1e10) continue;

		ll tugi0 = 1e18, tugi1 = 1e18;

		chmin(tugi1, dp0 + abs(L[i] - za0) + abs(L[i] - R[i]));
		chmin(tugi0, dp0 + abs(R[i] - za0) + abs(L[i] - R[i]));

		chmin(tugi1, dp1 + abs(L[i] - za1) + abs(L[i] - R[i]));
		chmin(tugi0, dp1 + abs(R[i] - za1) + abs(L[i] - R[i]));

		dp0 = tugi0;
		dp1 = tugi1;
		za0 = L[i];
		za1 = R[i];
	}

	co(min(dp0 + abs(za0), dp1 + abs(za1)));

	Would you please return 0;
}