import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto M = RD;
	auto dc = new long[][](M, 2);
	foreach (i; 0..M)
	{
		dc[i] = [RD, RD];
	}

	long[] g(long ed)
	{
		long d, ans;
		if (ed >= 10)
		{
			d = ed/10 + ed%10;
			ans += 2;
		}
		else
		{
			d = ed;
			++ans;
		}
		return [ans, d];
	}
	long[] f(long d, long c)
	{
		if (c == 0) return [0, 0];
		long lastD = d;
		auto x = 10 - d;
		auto cnt = min(d / x, c-1);
		long ans_t;
		ans_t += cnt;
		ans_t += max(0, cnt-1);
		d -= x * cnt;
		auto e = cnt;
		if (e != 0)
		{
			auto ed = e + d;
			auto gr = g(ed);
			ans_t += gr[0];
			d = gr[1];
		}
		long cnt2, cnt3;
		if (cnt != 0)
		{
			cnt2 = c / cnt;
			cnt3 = c % cnt;
		}
		auto ans_t2 = ans_t * cnt2;
		auto r1 = f(d, cnt2);
		auto r2 = f(lastD, cnt3);
		ans_t2 += r1[0] + r2[0];
		if (cnt2 == 0)
		{
			d = d * c;
			ans_t2 = c-1;
		}
		else if (cnt3 != 0)
		{
			auto ed = r1[1] + r2[1];
			auto gr = g(ed);
			ans_t += gr[0];
			d = gr[1];
		}
		return [ans_t2, d];
	}

	auto a = new long[](M);
	long ans;
	foreach (i; 0..M)
	{
		auto d = dc[i][0];
		auto c = dc[i][1];
		auto r = f(d, c);
		ans += r[0];
		debug writeln("a:", ans);
		a[i] = r[1];
	}
	debug writeln(a);
	foreach (i; 0..M-1)
	{
		auto r = g(a[i]+a[i+1]);
		ans += r[0];
		debug writeln("b:", ans);
		a[i+1] = r[1];
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}