#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
const int N=3e5+5;


int cnt[N];

main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin>>n>>k;
	for(int i=0; i<n; i++){
		int x;
		cin>>x;
		cnt[x]++;
		cnt[x]=min(cnt[x], k);
	}
	
	int ans=0;
	int rem=k;
	for(int i=0; i<N; i++){
		int cn=min(cnt[i], rem);
		if(cn==rem){
			continue;
		}
		else{
			ans+=i*(rem-cn);
			rem=cn;
		}
	}
	cout<<ans;
	
	return 0;
}
#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 raw_x) : x(raw_x) {
    if (x >= P || x < 0) {
    x %= P;
    if (x < 0) x += P;
  }
}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};
ostream& operator<<(ostream& s, const FiniteField& x) { s << x.Value(); return s; }

FiniteField Solve() {
  int n;
  cin >> n;
  int64 m;
  cin >> m;

  int64 s = 0;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
    s += xs[i];
  }

  if (m < s) {
    return 0;
  }
  int64 r = m - s;
  int64 g = s + n - 1;
  int64 a = r + g + 1;
  int64 b = g + 1;
  FiniteField x = 1;
  for (int64 i = 1; i <= b; i++) {
    x *= (a - i + 1);
    x /= i;
  }
  return x;
}

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

  cout << Solve() << endl;
}