#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int M;
    cin >> M;
    deque<pair<ll, ll>> dcA;
    deque<pair<ll, ll>> dcB;
    
    for(int i = 0; i < M; i++){
        ll d, c;
        cin >> d >> c;
        dcA.push_back(make_pair(d, c));
    }
    
    ll ans = 0;
    bool processingA = true;
    while(true){
        if(processingA){
            while(!dcA.empty()){
                pair<ll, ll> target = dcA.front();
                dcA.pop_front();
                
                if(target.first == 0){
                    ans += target.second;
                    continue;
                }else if(target.second == 1){

                    if(dcA.empty() && dcB.empty()){
                        cout << ans << "\n";
                        return 0;
                    }
                    
                    pair<ll, ll> next;
                    if(!dcA.empty()){
                        next = dcA.front();
                        dcA.pop_front();
                    }else{
                        next = dcB.back();
                        dcB.pop_back();
                    }
                    next.second--;
                    
                    target.first += next.first;
                    if(target.first >= 10){
                        ans += target.second;
                        target.first -= 9;
                    }
                    ans += target.second;
                    dcB.push_back(make_pair(target.first, target.second));
                    if(next.second != 0){
                        dcA.push_front(make_pair(next.first, next.second));
                    }
                    continue;
                }else if(target.second >= 2){
                    if(target.second % 2 == 1){
                        dcA.push_front(make_pair(target.first, 1));
                    }
                    
                    target.first *= 2;
                    target.second /= 2;
                    if(target.first >= 10){
                        ans += target.second;
                        target.first -= 9;
                    }
                    ans += target.second;
                    
                    dcB.push_back(make_pair(target.first, target.second));
                    continue;
                }
            }
        }else{
            while(!dcB.empty()){
                pair<ll, ll> target = dcB.front();
                dcB.pop_front();
                
                if(target.first == 0){
                    ans += target.second;
                    continue;
                }else if(target.second == 1){

                    if(dcA.empty() && dcB.empty()){
                        cout << ans << "\n";
                        return 0;
                    }
                    
                    pair<ll, ll> next;
                    if(!dcB.empty()){
                        next = dcB.front();
                        dcB.pop_front();
                    }else{
                        next = dcA.back();
                        dcA.pop_back();
                    }
                    next.second--;
                    
                    target.first += next.first;
                    if(target.first >= 10){
                        ans += target.second;
                        target.first -= 9;
                    }
                    ans += target.second;
                    dcA.push_back(make_pair(target.first, target.second));
                    if(next.second != 0){
                        dcB.push_front(make_pair(next.first, next.second));
                    }
                    continue;
                }else if(target.second >= 2){
                    if(target.second % 2 == 1){
                        dcB.push_front(make_pair(target.first, 1));
                    }
                    
                    target.first *= 2;
                    target.second /= 2;
                    if(target.first >= 10){
                        ans += target.second;
                        target.first -= 9;
                    }
                    ans += target.second;
                    dcA.push_back(make_pair(target.first, target.second));
                    continue;
                }
            }
        }
        processingA = !processingA;
    }
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6436