def f(map1,cs,x,y,w,h)
h2=map1[y][x]
c2=cs[y][x]
c2=h2 if c2==0
c1=0
[[0,1],[-1,0],[0,-1],[1,0]].each{|dy,dx|
x2=x+dx
y2=y+dy
next if x2<0 || w<=x2 || y2<0 || h<=y2
next if map1[y2][x2]<map1[y][x]
c1+=1
if cs[y2][x2]==0 then
cs[y2][x2]=c2
elsif 0<cs[y2][x2] && cs[y2][x2]!=cs[y][x]
cs[y2][x2]=10**18
end
}
if c1>0 then
cs[y][x]=c2
end
end
h,w=gets.split(" ").map{|e| e.to_i}
map1=[]
cs=[]
hs=[]
h.times{|y|
map1<<gets.split(" ").map{|e| e.to_i}
cs<<[]
w.times{|x|
t=map1[y][x]
hs<<[t,y,x]
cs[y]<<0
}
}
hs.sort!
hs.each{|t,y,x|
f(map1,cs,x,y,w,h)
}
ans=0
h.times{|y|
w.times{|x|
ans+=1 if cs[y][x]==10**18
}
}
puts ans
ZGVmIGYobWFwMSxjcyx4LHksdyxoKQoJaDI9bWFwMVt5XVt4XQoJYzI9Y3NbeV1beF0KCWMyPWgyIGlmIGMyPT0wCgljMT0wCglbWzAsMV0sWy0xLDBdLFswLC0xXSxbMSwwXV0uZWFjaHt8ZHksZHh8CgkJeDI9eCtkeAoJCXkyPXkrZHkKCQluZXh0IGlmIHgyPDAgfHwgdzw9eDIgfHwgeTI8MCB8fCBoPD15MgoJCW5leHQgaWYgbWFwMVt5Ml1beDJdPG1hcDFbeV1beF0KCQljMSs9MQoJCWlmIGNzW3kyXVt4Ml09PTAgdGhlbgoJCQljc1t5Ml1beDJdPWMyCgkJZWxzaWYgMDxjc1t5Ml1beDJdICYmIGNzW3kyXVt4Ml0hPWNzW3ldW3hdCgkJCWNzW3kyXVt4Ml09MTAqKjE4CgkJZW5kCgl9CglpZiBjMT4wIHRoZW4KCQljc1t5XVt4XT1jMgoJZW5kCmVuZApoLHc9Z2V0cy5zcGxpdCgiICIpLm1hcHt8ZXwgZS50b19pfQptYXAxPVtdCmNzPVtdCmh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