#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define pb push_back
#define pii pair<int,int>
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7,mxn=2e5 + 5;

signed main(){

  gok

  int n,m;
  cin>>n>>m;
  int gr[n][m];
  int mi=1e9;
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<m;j++)
      {
          cin>>gr[i][j];
          mi = min(mi,gr[i][j]);
      }
  }

  int an=0;

  for(int i=0;i<n;i++)
  {
      for(int j=0;j<m;j++)
      {
         an += gr[i][j]-mi;
      }
  }

cout<<an;




    return 0;
    }





#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define ll long long
using namespace std;
int main() {
	int n, q;
	cin >> n >> q;
	vector<ll> a;
	for(int i = 0; i < n; ++i) {ll x; cin >> x; a.push_back(x);}
	sort(a.begin(), a.end());
	//for (int i = 0; i < n; ++i) cout << a[i] << " ";
	//cout << endl;
	vector<ll>su;
	su.push_back(a[0] - 1);
	for (int i = 1; i < n; ++i) {
		ll k = (a[i] - a[i - 1] - 1);
		if (k < 0) k = 0;
		su.push_back(k);
	}
	//for (int i = 0; i < n; ++i) cout << su[i] << " ";
	//cout << endl;
	for (int i = 1; i < n; ++i) su[i] += su[i - 1];
	//for (int i = 0; i < n; ++i) cout << su[i] << " ";
	//cout << endl;	
	while(q--) {
		ll k1;
		cin >> k1;
		int in = lower_bound(su.begin(), su.end(), k1) - su.begin();
		if (in > 0) {
			ll suc = k1 - su[in - 1];
			//cout << "SU " << in << endl;
			//cout << suc << " " << k1  << " " << su[in - 1] << endl;
			cout << a[in - 1] + suc << endl;
		} else {
			//cout << "IN 0" << endl;
			cout << k1 << endl;
		}
	}
}