#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    
     int A[n];
    map< int,int>P;
    int mx=-1;
    for(int i=0;i<n;++i){
        cin>>A[i];
        P[A[i]]++;
        mx=max(mx,A[i]);
    }
     
    int c=0;
    
    int tot=0;int f=0,g=0;
    for(int i=0;i<=(mx+1);++i){
        m=min(m,P[i]);
        tot+=m;
    }
   cout<<tot<<endl;
    
}
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 12/19/20 19:28:51
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int h,w; cin>>h>>w;
  int minv = 1000;
  vector<vector<int>> A(h, vector<int>(w));
  for (auto& l:A) for (auto& v:l) {
    cin>>v;
    minv = min(minv, v);
  }
  int ans = 0;
  for (auto& l:A) for (auto& v:l) {
    ans += v-minv;
  }
  cout << ans << endl;
  

  return 0;
}
