#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


bool visited[10][10];

using Item = tuple<ll,ll,ll>;
Item loop_info[10];
pll dep_info[10][10];
template<class Type>
Type solve(Type res = Type()){
    ll M; cin >> M;
    vector<ll> d(M),c(M);
    for(int i = 0; i < M;i++){
        cin >> d[i] >> c[i];
    }
    
    for(int s = 0; s < 10;s++){
        
        ll n = s;
        ll info1 = 1; // 何桁目か
        ll info2 = 0; // 何回開催できるか
        
        while(true){
            if(visited[s][n]){
                loop_info[s] =
                    Item(n,
                         info1 - dep_info[s][n].first,
                         info2 - dep_info[s][n].second);
                break;
            }
            
//            cout << "s : " << s << endl;
//            cout << n << " " << info1 << " " << info2 << endl;
//            cout << endl;
            visited[s][n] = true;
            dep_info[s][n] = pll(info1,info2);
            
            info1++;
            n = n + s; info2++;
            if(n >= 10){
                n = n/10 + n%10; info2++;
            }
        }
    }
    
    stack<ll> st;
    
    for(int i = 0; i < M;i++){
        ll s = d[i];
        ll nd = s;
        ll nc = c[i];
        
        
        ll loop_n,info1,info2;
        tie(loop_n,info1,info2) = loop_info[s];
        
//        cout << s << " " << loop_n << " " << info1 << " " << info2 << endl;
//        cout << dep_info[s][loop_n] << endl;

        if(dep_info[s][loop_n].first <= nc){ // ループ回数よりも個数が多いのであれば
            // ループ起点まで移動
            nd = loop_n;
            nc -= dep_info[s][loop_n].first;
            res += dep_info[s][loop_n].second;
            
            ll x = nc/info1; // 何回ループできるか
            
            //　ループ
            nc -= x * info1;
            res += x * info2;
        }

        // 愚直に試す
        while(nc){
            nc--;
            nd = nd + s; res++;
            if(nd >= 10){
                nd = nd/10 + nd%10; res++;
            }
        }
        st.push(nd);
        
    }
    
    while(st.size() >= 2){
        ll l,r;
        r = st.top(); st.pop();
        l = st.top(); st.pop();
        
        res++;
        ll lr = l + r;
        if(lr >= 10){
            lr = lr/10 + lr%10; res++;
        }
        
        st.push(lr);
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 4992