#pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize ("Ofast")
        #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
        #include <iostream>
        #include <iomanip>
        #include <sstream>
        #include <cstring>
        #include <vector>
        #include <deque>
        #include <queue>
        #include <set>
        #include <map>
        #include <valarray>
        #include <iterator>
        #include <functional>
        #include <limits>
        #include <algorithm>
        #include <numeric>
        #include <cmath>
        #include <cassert>
        #include <unordered_map>
        #include <unordered_set>
        #include <stack>
        using namespace std;
        #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
         #define trace(x) cerr << #x << ": " << x << " " << endl;
     
        typedef int64_t ll;
     
        #define endl '\n'
        #define int ll
        ll mod=1e9+7;
        ll mod1=1e9+5;
        ll power(ll a,ll b)
        {
            if(b==0) return 1;
            else if(b%2==0)
                return power((((a%mod)*(a%mod))%mod),b/2)%mod;
            else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
        }
        
     int32_t main()
        {
        IOS
     

            
            
            map<int,int> m;
            map<int,int> m1;
            for(int i=1;i<=9;++i){
                int curr=i;
                int p=0;
                int q=1;
            while(1)
            {               
                
                p++;
                if(curr/10==0)
                    curr+=i,q++;
                else
                {
                    curr=curr/10+curr%10;
                }
                if(curr==i)
                    break;
            }
            m[i]=p;
            m1[i]=q;
           // cout<<p<<endl;
        }
        vector<int> v;
        int t;
        cin>>t;
        int ans=0;
        for(int i=0;i<t;++i)
        {
            int x,y;
            cin>>x>>y;
            if(x==0)
            {
                ans+=y-1;
                v.push_back(x);
            }
            else
            {

                while(1)
                {
                    if(m1[x]>=y)
                    {
                        for(int i=1;i<=y;++i)
                        {
                            v.push_back(x);
                        }
                        break;
                    }
                    else
                    {
                        ans+=m[x]*(y/m1[x]);
                        y=y/m1[x]+y%m1[x];
                    }
                }
            }
        }
        // for(int i=0;i<v.size();++i)
        //     cout<<v[i]<<" ";
        int i=1;
        int curr=v[0];
        while(1)
        {
             if(i==v.size() and curr/10==0)
                break;
            if(curr/10==0)
            {
                curr+=v[i];
                i++;
                ans++;
            }
            else
            {
                curr=curr/10+curr%10;
                ans++;
            }

        }
        cout<<ans;


        }

Measured memory_bytes: 10092