import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        try {
            if (!sc.hasNextInt()) {
                System.out.println("Invalid input");
                return;
            }
            int n = sc.nextInt();
            sc.nextLine(); // consume newline

            // Check constraint on n
            if (n < -20 || n > 20) {
                System.out.println("Invalid input");
                return;
            }

            int totalCalories = 0;

            for (int i = 0; i < n; i++) {
                if (!sc.hasNextLine()) {
                    System.out.println("Invalid input");
                    return;
                }
                String line = sc.nextLine().trim();
                String[] parts = line.split("\\s+");

                if (parts.length != 3) {
                    System.out.println("Invalid input");
                    return;
                }

                String foodType = parts[0];
                int qty, cal;

                // Validate type
                if (!(foodType.equals("Fruit") || foodType.equals("Vegetable") || foodType.equals("Dairy"))) {
                    System.out.println("Invalid input");
                    return;
                }

                try {
                    qty = Integer.parseInt(parts[1]);
                    cal = Integer.parseInt(parts[2]);
                } catch (NumberFormatException e) {
                    System.out.println("Invalid input");
                    return;
                }

                // If negative qty or cal → print -1
                if (qty < 0 || cal < 0) {
                    System.out.println(-1);
                    return;
                }

                totalCalories += qty * cal;
            }

            System.out.println(totalCalories);

        } catch (Exception e) {
            System.out.println("Invalid input");
        }
    }
}
