#include <iostream>
using namespace std;
int Shortest(int arr[], int len){
int s=arr[0];
for(int i=1; i<=len-1; i++){
if(arr[i]<s) s=arr[i];
}return s;
}
int main() {
int H, W;
int x=0;
cin>>H>>W;
int arr[100];
for(int i=0; i<H*W; i++){
cin>>arr[i];
}
int y=Shortest(arr, H*W);
for(int j=0; j<H*W; j++){
if(arr[j]==y) x=x+0;
else x=x+(arr[j]-y);
}
cout<<x;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgU2hvcnRlc3QoaW50IGFycltdLCBpbnQgbGVuKXsKICBpbnQgcz1hcnJbMF07CiAgZm9yKGludCBpPTE7IGk8PWxlbi0xOyBpKyspewogICAgaWYoYXJyW2ldPHMpIHM9YXJyW2ldOwogIH1yZXR1cm4gczsKfQppbnQgbWFpbigpIHsKCWludCBILCBXOwoJaW50IHg9MDsKCWNpbj4+SD4+VzsKCWludCBhcnJbMTAwXTsKICAgIGZvcihpbnQgaT0wOyBpPEgqVzsgaSsrKXsKICAgIAljaW4+PmFycltpXTsKICAgIH0KICAgIGludCB5PVNob3J0ZXN0KGFyciwgSCpXKTsKCWZvcihpbnQgaj0wOyBqPEgqVzsgaisrKXsKCQlpZihhcnJbal09PXkpIHg9eCswOwoJCWVsc2UgeD14KyhhcnJbal0teSk7CiAgICB9CiAgICBjb3V0PDx4Owp9