import java.util.*;

public class GameScore {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); // number of actions

        // Constraint: number of actions cannot be < 0
        if (n < 0) {
            System.out.println("Invalid input");
            return;
        }
        // If n = 0 → also invalid input (as per sample)
        if (n == 0) {
            System.out.println("Invalid input");
            return;
        }

        int score = 0;

        for (int i = 0; i < n; i++) {
            int type = sc.nextInt();
            int points = sc.nextInt();

            // Check action type validity
            if (type != 1 && type != 2) {
                System.out.println("-1");
                return;
            }

            // Check points validity (1 to 100)
            if (points < 1 || points > 100) {
                System.out.println("-1");
                return;
            }

            // Perform action
            if (type == 1) {
                score += points;
            } else { // type == 2
                score -= points;
            }
        }

        // Print final score
        System.out.println(score);
    }
}