#!/usr/bin/perl -w

use v5.16;
use strict;

use JSON qw(from_json);

my $j = from_json(<>);

my $sum;

sub walk {
	my $r = shift;
	if (ref $r && ref $r eq 'ARRAY') {
		for my $member (@$r) {
			walk($member);
		}
	} elsif (ref $r && ref $r eq 'HASH') {
		for my $k (keys %$r) {
			return if $r->{$k} eq 'red';
		}
		for my $k (keys %$r) {
			walk($r->{$k});
		}
	} elsif ($r =~ /\A-?\d+\z/) {
		$sum += $r;
	}
}

walk($j);
say $sum;
