#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(), cout.tie();
  long long n, m, sum = 0;
  cin >> n >> m;
  long long a[n + 1];
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  a[n] = 1e10;
  sort(a, a + n);
  long long cur = 0, ans = 0, start = 0, e = 0, h = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1]) {
      long long x = i - start;
      start = i;
      long long d = a[i - 1] - cur;
      long long mn = 0;
      if (d > x) {
        e += d - x;
      } else {
        h += x - d;
        mn = min(e, h);
        e -= mn;
        h = 0;
        ans += mn;
      }
      ans += (x - mn);
      cur = a[i - 1];
    }
  }
  ans += e;
  cout << sum - ans << endl;
  return 0;
}
