#!/usr/bin/perl -w

use v5.36;
use strict;
use experimental 'multidimensional';
use List::Util qw(none);

my @m = map { chomp; [ split // ] } <>;
my $xmax = @{ $m[0] };
my $ymax = @m;

my $count;
for my $y (1 .. $ymax-2) {
for my $x (1 .. $xmax-2) {
	my $visible = sub { none { $m[$_->[1]][$_->[0]] >= $m[$y][$x] } @_; };
	$count++
		if $visible->( map { [ $_, $y ] } 0 .. $x-1 )
		|| $visible->( map { [ $_, $y ] } $x+1 .. $xmax-1)
		|| $visible->( map { [ $x, $_ ] } 0 .. $y-1)
		|| $visible->( map { [ $x, $_ ] } $y+1 .. $ymax-1)
		;
} }

say $count + 2*$xmax + 2*$ymax - 4;
