import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	X[] as;
	foreach(i; 0 .. n){
		as ~= X(rlong, rlong);
	}
	
	long[] bs;
	long ans;
	foreach(a; as){
		if(1){
			long l = a.length % 9;
			if(l == 0) l = 9;
			foreach(i; 0 .. l) bs ~= a.digit;
			ans += (a.digit + 9) * ((a.length - l) / 9);
			log("a:", a, "ans:", ans);
		}
		else{
			foreach(i; 0 .. a.length) bs ~= a.digit;
		}
	}
	log("bs:", bs);
	
	ans -= 1;
	long x;
	foreach(b; bs){
		if(x + b < 10) x = x + b, ans += 1;
		else x = x + b - 9, ans += 2;
		log("b:", b, "x:", x, "ans:", ans);
	}
	
	ans.writeln;
	
}
struct X{
	long digit;
	long length;
}

/*
実は、左から順に消していけば良い。
同じ数字が続くところはシミュレーションしておく。周期になるはず。
周期とその時の回数はこう
	int[] zs = [1, 9, 9, 3, 9, 9, 3, 9, 9, 1];
	int[] ys = [9, 10, 11, 4, 13, 14, 5, 16, 17, 2];
	
つまり周期9で, 9 + i をたせばよい

*/
