// JOI2019.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
typedef pair <ll, ll> P;
ll gcd(ll a, ll b) {//最大公約数を求める
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	ll x = gcd(a, b);
	return a * b / x;
}
/***************///オイラーの小定理による組み合わせ//**********/
/*static const ll N = 4e5;
const ll MOD = 1e9 + 7;
ll fact[N], invfact[N];
ll pow(ll a, ll b, ll m)
{
	ll ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

ll modinv(ll k)
{
	return pow(k, MOD - 2, MOD);
}

void precompute()
{
	fact[0] = fact[1] = 1;
	for (ll i = 2; i < N; i++)
	{
		fact[i] = fact[i - 1] * i;
		fact[i] %= MOD;
	}
	invfact[N - 1] = modinv(fact[N - 1]);
	for (ll i = N - 2; i >= 0; i--)
	{
		invfact[i] = invfact[i + 1] * (i + 1);
		invfact[i] %= MOD;
	}
}

ll nCr(ll x, ll y)
{
	if (y > x)
		return 0;

	ll num = fact[x];
	num *= invfact[y];
	num %= MOD;
	num *= invfact[x - y];
	num %= MOD;
	return num;
}*/
/************************組み合わせおわり*****************************/
/*int bit[10000000], bit_n;
int sum(int i) {
	int s = 0;
	while (i > 0) {
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void add(int i, int x) {
	while (i, i <= bit_n) {
		bit[i] += x;
		i += i & -i;
	}
}*/
int M;
ll c[200005], d[200005];
ll num[12];
int main() {
	cin >> M;
	rep(i, M) {
		cin >> d[i] >> c[i];
		num[d[i]] += c[i];
	}
	ll ans = 0;
	
	while (true) {
		bool flag = true;
		rep(i, 10) {
			if (num[i] >= 2) {
				flag = false;
				
			}
		}
		if (flag)break;
		for (int i = 0; i < 10; ++i) {
			if (num[i] < 2)continue;
			const ll x = num[i];
			if (i == 9) {
				num[1] += (x / 2);
				num[8] += (x / 2);
			}
			else if (i == 8) {
				num[1] += (x / 2);
				num[6] += (x / 2);
			}
			else if (i == 7) {
				num[1] += (x / 2);
				num[4] += (x / 2);
			}
			else if (i == 6) {
				num[1] += (x / 2);
				num[2] += (x / 2);
			}
			else if (i == 5) {
				num[1] += (x / 2);
				num[0] += (x / 2);
			}
			else {
				num[i + i] += (x / 2);
			}
			
		
			num[i] -= (x/2) * 2;
				ans += (x / 2);
			
		}
		
	}
	
	while (true) {
		ll res = 0;
		rep(i, 10) {
			res += num[i];
			
		}
		if (res < 2)break;
		rep(i, 10) {
			for (int j = i; j < 10; j++) {
				if (num[i] > 0 && num[j] > 0) {
					if (i == j && num[i] <= 1)continue;
					else {
						
						if (i + j >= 10) {
							num[1]++;
							num[i + j - 10]++;
						}
						else {
							num[i + j]++;
						}
						num[i]--; num[j]--;
						ans++;
						break;
					}
				}
			}
		}
	}
	cout << ans << endl;


}

Measured memory_bytes: 3328