#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> blocks;
void takeInput(void) {
  long long val;
  cin >> n >> m;
  for (int i = 0; i < (n); i++) {
    cin >> val;
    blocks.push_back(val);
  }
}
long long bsearch(long long ind, long long val) {
  long long end = -1;
  long long l = ind + 1, r = n - 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (blocks[mid] > val) {
      end = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return end;
}
void solve() {
  sort(blocks.begin(), blocks.end());
  long long res = 0;
  long long currBlock = 1;
  long long i = 0;
  while (i < n) {
    if (blocks[i] < currBlock) {
      i++;
      continue;
    }
    long long nextIndex = bsearch(i, currBlock);
    if (nextIndex == -1) {
      if (i < n - 1) {
        res += (blocks[i] - currBlock);
      }
      i++;
    } else {
      res += (blocks[i] - currBlock);
      res += (n - nextIndex);
      currBlock++;
      i = nextIndex;
    }
  }
  cout << res << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  takeInput();
  solve();
  return 0;
}
