let () =
    let calc1 d c =
        let restv = Array.make 10 (-1) in
        let accv  = Array.make 10 (-1) in
        let rec loop v rest acc =
            if rest = 0 then v, acc else
                if restv.(v) >= 0 then (
                    let cycle = restv.(v) - rest in
                    let acyc  = acc - accv.(v) in
                    restv.(v) <- -1;
                    accv.(v) <- -1;
                    let count = rest / cycle in
                    let rest = rest - count * cycle in
                    let acc =  acc  + count * acyc in
                    loop v rest acc 
                ) else (
                    restv.(v) <- rest;
                    accv.(v) <- acc;
                    let v = v + d in
                    if v >= 10 then loop ((v / 10) + (v mod 10)) (rest - 1) (acc + 2) else
                                    loop v (rest - 1) (acc + 1)
                )
        in
        if c = 1 then d, 0 else
            let v = d * 2 in
            if v >= 10 then loop ((v / 10) + (v mod 10)) (c - 2) 2 else loop v (c - 2) 1 
    in
    let calc2 dc =
        let rec loop cur acc = function
            | [] -> acc
            | (v, s) :: tl ->
                    let v = v + cur in
                    if v >= 10 then loop ((v / 10) + (v mod 10)) (acc + s + 2) tl else loop v (acc + s + 1) tl
        in
        loop 0 (-1)dc
    in
    let main () =
        let m = int_of_string (read_line ()) in
        let dc = Array.init m (fun _ -> Scanf.sscanf (read_line ()) "%d %d" calc1) in
        let r = calc2 (Array.to_list dc) in
        Printf.printf "%d\n" r
    in
    main ()