/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
2
2 2
9 1
---+/
/+---test
3
1 1
0 8
7 1
---+/

void main(string[] args) {
  const M = readln.chomp.to!long;

  long[] digits;
  foreach (i; 0..M) {
    long d, c;
    readf(" %d %d ", &d, &c);
    foreach (j; 0..c) digits ~= d;
  }

  auto sums = new long[digits.length-1];
  foreach (i, ref v; sums) {
    v = digits[i] + digits[i+1];
  }

  long ans;
  while (sums.length > 0) {
    if (sums[0] < 10) {
      digits = sums[0]~digits[1..$];
      sums   = sums[1..$];
    } else {
      digits[0] = sums[0]/10;
      digits[1] = sums[0]%10;
    }

    foreach (i; 0..min(2, sums.length)) {
      sums[i] = digits[i] + digits[i+1];
    }
    ++ans;
  }
  ans.writeln;
}
