#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+0;
else x+(arr[j]-y);
}
cout<<x;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgU2hvcnRlc3QoaW50IGFycltdLCBpbnQgbGVuKXsKICBpbnQgcz1hcnJbMF07CiAgZm9yKGludCBpPTE7IGk8PWxlbi0xOyBpKyspewogICAgaWYoYXJyW2ldPHMpIHM9YXJyW2ldOwogIH1yZXR1cm4gczsKfQppbnQgbWFpbigpIHsKCWludCBILCBXOwoJaW50IHg9MDsKCWNpbj4+SD4+VzsKCWludCBhcnJbMTAwXTsKICAgIGZvcihpbnQgaT0wOyBpPD1IKlc7IGkrKyl7CiAgICAJY2luPj5hcnJbaV07CiAgICB9CiAgICBpbnQgeT1TaG9ydGVzdChhcnIsIEgqVyk7CgkJZm9yKGludCBqPTA7IGo8PUgqVzsgaisrKXsKCQlpZihhcnJbal09PXkpIHgrMDsKCQllbHNlIHgrKGFycltqXS15KTsKICAgIH0KICAgIGNvdXQ8PHg7Cn0=