import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void next (int x, int y, ref int l, out int z) {
  x += y;
  ++l;
  if (x < 10) {
    z = x;
    return;
  }
  z = x - 9;
  ++l;
}

alias T = Tuple!(int, int);

void main() {
  int m;
  readf (" %d", &m);
  auto d = new int[m];
  auto c = new long[m];
  foreach (i; 0 .. m) {
    readf (" %d %d", &d[i], &c[i]);
  }
  int u = d[0]; --c[0];
  ulong res;
  debug stderr.writeln ("d = ", d);
  debug stderr.writeln ("c = ", c);
  debug stderr.writeln ("u = ", u);
  foreach (i; 0 .. m) {
    debug stderr.writefln ("u = %d, i = %d, c[i] = %d, d[i] = %d", u, i, c[i], d[i]);
    T[10] e = tuple (-1, -1);
    //delta_l, k
    e[u] = tuple (0, 0);
    immutable di = d[i];
    immutable ci = c[i];
    long k;
    for (k = 1; k <= ci; ++k) {
      int l, v;
      next (u, di, l, v);
      debug stderr.writeln ("next -> ", v);
      res += l;
      if (e[v][0] >= 0) {
        immutable p = k.to!int - e[v][1];
        immutable dl = l - e[v][0]; 
        long r = ci - k;
        long t = r / p;
        k = r % p;
        res += t * dl;
        u = v;
        break;
      }
      e[v] = tuple (l, k.to!int);
      u = v;
    }
    debug stderr.writeln ("k = ", k);
    if (k > ci) k = 0;
    int l = 0;
    while (k > 0) {
      int v;
      next (u, d[i], l, v);
      u = v;
      --k;
    }
    res += l;
    debug stderr.writefln ("res = %d, u = %d", res, u);
  }
  writeln (res);
}

