#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;

pair<LLI,int> calc(vector<int> s){
  LLI ret = 0;

  while(s.size() > 1){
    int a = s.back(); s.pop_back();
    int b = s.back(); s.pop_back();

    if(a+b >= 10){
      s.push_back(1);
      s.push_back((a+b)%10);
    }else{
      s.push_back(a+b);
    }

    ++ret;
  }

  return make_pair(ret, s[0]);
}

pair<LLI,int> merge(pair<LLI,int> a, pair<LLI,int> b){
  return make_pair(a.fst+b.fst, b.snd);
}


pair<LLI,int> sub(int d, LLI c){
  
  switch(d){
  case 0: {
    return make_pair(c-1, 0);
  }

  case 1: {
    pair<LLI,int> ret((c/9) * 8, 0);
    vector<int> b;

    if(c/9){
      auto a = sub(9, c/9);
      ret = merge(ret, a);
      b.push_back(a.snd);
    }

    {
      REP(i,c%9){
        b.push_back(d);
      }

      auto a = calc(b);
      ret = merge(ret, a);
    }

    return ret;
  }

  case 2: {
    pair<LLI,int> ret((c/5)*5, 0);
    vector<int> b;

    if(c/5){
      auto a = sub(1, c/5);
      ret = merge(ret, a);
      b.push_back(a.snd);
    }

    {
      REP(i,c%5){
        b.push_back(d);
      }

      auto a = calc(b);
      ret = merge(ret, a);
    }

    return ret;
  }

  case 3: {
    pair<LLI,int> ret((c/3) * 2, 0);
    vector<int> b;

    if(c/3){
      auto a = sub(9, c/3);
      ret = merge(ret, a);
      b.push_back(a.snd);
    }

    {
      REP(i,c%3){
        b.push_back(d);
      }

      auto a = calc(b);
      ret = merge(ret, a);
    }

    return ret;
  }

  case 4: {
    pair<LLI,int> ret((c/5) * 5, 0);
    vector<int> b;

    if(c/5){
      auto a = sub(1, (c/5)*2);
      ret = merge(ret, a);
      b.push_back(a.snd);
    }

    {
      REP(i,c%5){
        b.push_back(d);
      }

      auto a = calc(b);
      ret = merge(ret, a);
    }

    return ret;    
  }

  case 5: {
    pair<LLI,int> ret((c/2) * 2, 0);
    vector<int> b;

    if(c/2){
      auto a = sub(1, c/2);
      ret = merge(ret, a);
      b.push_back(a.snd);
    }

    {
      REP(i,c%2){
        b.push_back(d);
      }

      auto a = calc(b);
      ret = merge(ret, a);
    }

    return ret;
  }

  case 6: {
    pair<LLI,int> ret((c/3) * 3, 0);
    vector<int> b;

    if(c/3){
      auto a = sub(9, c/3);
      ret = merge(ret, a);
      b.push_back(a.snd);
    }

    {
      REP(i,c%3){
        b.push_back(d);
      }

      auto a = calc(b);
      ret = merge(ret, a);
    }

    return ret;
  }

  case 7: {
    pair<LLI,int> ret((c/3) * 2, 0);
    vector<int> b;

    if(c/3){
      auto a = sub(1, (c/3)*3);
      ret = merge(ret, a);
      b.push_back(a.snd);
    }

    {
      REP(i,c%3){
        b.push_back(d);
      }

      auto a = calc(b);
      ret = merge(ret, a);
    }

    return ret;
    
  }

  case 8: {
    pair<LLI,int> ret((c/5) * 5, 0);
    vector<int> b;

    if(c/5){
      auto a = sub(1, (c/5)*4);
      ret = merge(ret, a);
      b.push_back(a.snd);
    }

    {
      REP(i,c%5){
        b.push_back(d);
      }

      auto a = calc(b);
      ret = merge(ret, a);
    }

    return ret;
  }

  case 9: {
    return make_pair((c-1)*2, 9);
  } 
  }

  return make_pair(0, 0);
}




int main(){
  int m;
  while(cin >> m){
    vector<LLI> d(m), c(m);
    REP(i,m){
      cin >> d[i] >> c[i];
    }


    LLI ret = 0;
    
    vector<int> a;
    REP(i,m){
      auto res = sub(d[i], c[i]);
      dump(res);
      a.push_back(res.snd);
      ret += res.fst;
    }

    ret += calc(a).fst;

    cout << ret << endl;
  }

  return 0;
}


Measured memory_bytes: 5108