/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  
  lint n; cin >> n;
  vector<lint> d(n);
  vector<lint> c(n);
  for(int i = 0; i < n; i++) cin >> d[i] >> c[i];
  lint ans = 0;

  vector<lint> vec;

  for(int i = 0; i < n; i++) {
    vector<lint> rest;
    // cerr << c[i] << endl;
    while(c[i] > 1) {
      // cerr << i << " " << c[i] << " " << d[i] << endl;
      ans += c[i] / 2;
      if(c[i] % 2 == 1) rest.push_back(d[i]);
      d[i] = d[i] * 2;
      if(d[i] >= 10) {
        ans += c[i] / 2;
        d[i] = d[i] % 10 + d[i] / 10;
      }
      c[i] = c[i] / 2;
    }

    rest.push_back(d[i]);

    // 順番に処理
    while(rest.size() > 1) {
      int a = rest.back();
      rest.pop_back();
      int b = rest.back();
      rest.pop_back();
      int add = a + b;
      ans += 1;
      if(add >= 10) {
        add = add % 10 + add / 10;
        ans += 1;
      }

      rest.push_back(add);
    }

    vec.push_back(rest[0]);
  }
 
  // cerr << ans << endl;
  // for(int i = 0; i < vec.size(); i++) cerr << vec[i] << " ";
  // cerr << endl;
  while(vec.size() > 1) {
    int a = vec.back();
    vec.pop_back();
    int b = vec.back();
    vec.pop_back();
    int add = a + b;
    ans += 1;
    if(add >= 10) {
      add = add % 10 + add / 10;
      ans += 1;
    }

    vec.push_back(add);
    /* for(int i = 0; i < vec.size(); i++) cerr << vec[i] << " ";
    cerr << endl; */
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5492