N = int(input()) M_list = [] K = 0 for i in range(N): T, S = input().split(' ') T = int(T) kukan = len(S) K += kukan taka = 12 * T // 1000 if kukan > taka: m = kukan - taka #それぞれの区間でのミス M_list.append(m) M = sum(M_list) #ミスの合計 A = K - M print(A)