#!/usr/bin/perl -w

use v5.16;

my @m = map { chomp; [ split // ]; } <>; 
my $maxy = $#m;
my $maxx = $#{$m[0]};
say "$maxx x $maxy";

my $sum;
for my $y (0 .. $maxy) {
	for my $x (0 .. $maxx) {
		my $val = $m[$y][$x];
		next if $y > 0     && $m[$y-1][$x] <= $val;
		next if $y < $maxy && $m[$y+1][$x] <= $val;
		next if $x > 0     && $m[$y][$x-1] <= $val;
		next if $x < $maxx && $m[$y][$x+1] <= $val;
		say "found at $x $y";
		$sum += $val + 1;
	}
}

say $sum;

