let () =
    let calc1 d c =
        let rec loop v rest acc =
            if rest = 0 then v, acc else
                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 ()