You came to the exhibition and one exhibit has drawn your attention. It consists of $n$ stacks of blocks, where the $i$-th stack consists of $a_i$ blocks resting on the surface.

The height of the exhibit is equal to $m$. Consequently, the number of blocks in each stack is less than or equal to $m$.

There is a camera on the ceiling that sees the top view of the blocks and a camera on the right wall that sees the side view of the blocks.$\text{Top View}$ 

Find the maximum number of blocks you can remove such that the views for both the cameras would not change.

Note, that while originally all blocks are stacked on the floor, it is not required for them to stay connected to the floor after some blocks are removed. There is no gravity in the whole exhibition, so no block would fall down, even if the block underneath is removed. It is not allowed to move blocks by hand either.


-----Input-----

The first line contains two integers $n$ and $m$ ($1 \le n \le 100\,000$, $1 \le m \le 10^9$) — the number of stacks and the height of the exhibit.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$) — the number of blocks in each stack from left to right.


-----Output-----

Print exactly one integer — the maximum number of blocks that can be removed.


-----Examples-----
Input
5 6
3 3 3 3 3

Output
10
Input
3 5
1 2 4

Output
3
Input
5 5
2 3 1 4 4

Output
9
Input
1 1000
548

Output
0
Input
3 3
3 1 1

Output
1


-----Note-----

The following pictures illustrate the first example and its possible solution.

Blue cells indicate removed blocks. There are $10$ blue cells, so the answer is $10$.[Image]

Difficulty: interview

Starter code:

Solutions:
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
mx = a[-1]
t = 0
ans = 0;
for i in a:
    if i > 0:
        if i > t:
            t += 1
        ans += i - 1
ans -= mx - t
print(ans)


#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, M = getIntList()

za  = getIntList()
za.sort(reverse = True)

re = 0

for i in range(N-1):
    a = za[i]
    b = za[i+1]
    g = b
    if g>=a:
        t = a-1
        if t<1: t = 1
        re +=  g-t
        za[i+1] = t
        re += a - 1
    else:
        re += g
print(re)








3

import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, M, A):
    A.sort(reverse=True)

    lh = A[0]
    cnt = 1
    for a in A[1:]:
        if lh == 1:
            cnt += 1
        elif lh - 1 <= a:
            cnt += 1
            lh -= 1
        else:
            cnt += lh - a
            lh = a

    cnt += lh - 1

    return sum(A) - cnt


def main():
    N, M = [int(e) for e in inp().split()]
    A = [int(e) for e in inp().split()]
    assert len(A) == N
    print(solve(N, M, A))


def __starting_point():
    main()

__starting_point()

n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
worst=0
maxi=a[0]
a.append(0)
for i in range(n+1):
    bad=maxi-a[i]-i
    worst=max(worst,bad)
print(sum(a)-n-worst)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
h = 0
ans = 0
for i in range(n - 1):
    ans += a[i] - 1
    if a[i] > h:
        h += 1
if h < max(a):
    ans += h
else:
    ans += a[-1] - 1
print(ans)
        


n, m = list(map( int, input().split() ))
a = list( map( int, input().split() ) )

ans = sum( a )
a.sort()
lastlevel = 0
level = 0
got = 0

for i in a:
    got = max( got, i )
    level = min( level + 1, got )
    if i > 0:
        ans -= 1
        lastlevel = level

ans -= ( got - level )
print( ans )


n, m = list(map(int, input().split()))
a = sorted(map(int, input().split()))
ans = 0
cur = 0
for b in a:
  if b > cur:
    ans += 1
    cur += 1
  else:
    ans += 1
print(sum(a) - (ans + max(a) - cur))


from collections import Counter as C
n, m = map(int, input().split())
l = [*map(int, input().split())]
c = sorted(C(l).items())

res = 0
j = 0
for hi, ni in c:
    # print(hi, ni, j)
    h = min(hi - j, ni) + j
    res += (hi - 1) * ni 
    if h > j:
        j = h
m = max(l)
if j < m:
    res -= m - j
print(res)

import math as ma
import sys
from decimal import Decimal as dec
from itertools import permutations


def li():
	return list(map(int , input().split()))


def num():
	return map(int , input().split())


def nu():
	return int(input())


n,m=num()
a=li()
ind=-1
z=0
ll=sorted(a)
mx=ll[n-1]-1
cc=0
for i in range(n-2,-1,-1):
	if (ll[i] == 0):
		continue
	if(mx==0):
		cc += ll[i] - 1
		continue

	if(ll[i]>=mx):
		cc+=1
		mx-=1
		cc+=ll[i]-1
		ll[i]=1
	else:
		mx=ll[i]
		cc+=1
		mx-=1
		cc += ll[i] - 1
		ll[i] = 1

print(cc)

n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
c = sum(a)
if n == 1:
	print(0)
	return
a.sort()
res = 0
pocl = a[n - 1]
f = False
for i in range(n - 2, -1, -1):
	if pocl > 1:
		if a[i] >= pocl:
			res += 1
			pocl -= 1
			res += (a[i] - 1)
		else:
			f = True
			pocl = a[i]
			res += 1
			res += (a[i] - 1)
			pocl -= 1
	elif pocl == 1:
		if f:
			res += 1
		res += (a[i] - 1)
		pocl -= 1
	else:
		res += (a[i] - 1)
	#print(res, pocl)
print(res)
	


import sys
input_file = sys.stdin

[n,m] = list(int(x) for x in input_file.readline().split())
stacks = list(int(x) for x in input_file.readline().split())
stacks.sort()

ans = 0
cur_stack = 0
cur_h = 0

while cur_stack < n:
    ans += 1
    if stacks[cur_stack] >= cur_h + 1:
        cur_h += 1
    cur_stack += 1
ans += stacks[-1] - cur_h 
    
print(sum(stacks) - ans)


n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
res = 0
same = 0
p = 1
for h in a:
	if p <= h:
		p += 1
	else:
		same += 1
res = a[-1] + same
print(sum(a) - res)

n, m = map(int, input().split())
a = list(map(int, input().split()))
h = max(a)
a.sort()
a.reverse()
a.append(0)
ans = sum(a)
for i in range(n):
    if a[i + 1] >= a[i]:
        a[i + 1] = a[i] - 1
    ans -= max(a[i] - a[i + 1], 1)
print(ans)

import math
n, m=map(int, input().split())
a=sorted(list(map(int, input().split())))
res=0
nr=1
f=1
for i in range(len(a)-1):
  if (a[i]!=0):
    if (a[i]==1):
      nr=2
      continue
    if (nr>a[i]):
      res+=max(0, max(0, nr-1)-1)
    else:
      res+=max(0, a[i]-nr)+max(0, nr-1)
    if (a[i]-nr>=0):
      f=0
    if (f==0):
      nr+=1
      f=1
if (nr>a[-1]):
  res+=max(0, max(0, nr-1)-1)
else:
  res+=max(0, nr-1)
print (res)

n,m=map(int,input().split())
arr=[ int(x) for x in input().split()]

arr=sorted(arr,reverse=True)
arr.append(0)
#print(arr)
isum=sum(arr)
ans=[]
top=arr[0]
for i in range(n):
	if(arr[i]==1):
		ans.append(1)
		arr[i+1]=1
		continue
	if(arr[i+1] >arr[i]):
		arr[i+1]=arr[i]
	if arr[i]-arr[i+1]==0:
		ans.append(1)
		h=1
	else:
		ans.append(arr[i]-arr[i+1])
		h=arr[i]-arr[i+1]

	top=arr[i]-h
	arr[i+1]=top
# 	print("top:",top)
# 	print("arr:",arr)
# 	print("ans:",ans)
# print(ans)
print(isum-sum(ans))

n, m = map(int, input().split())
a = [0] + list(map(int, input().split()))
a.sort()
ans = 0
h = a[-1]
for i in range(n, 0, -1):
	if a[i - 1] < h - 1:
		ans = ans + a[i] - h + a[i - 1]
		h = a[i - 1]
	else:
		ans = ans + a[i] - 1
		h = h - 1
print(ans)

import sys

n,m=list(map(int,input().split()))
A=list(map(int,input().split()))

if n==1:
    print(0)
    return

A.sort(reverse=True)

NOW=A[0]
ANS=1
i=1
while i<n:
    if A[i]==A[i-1]:
        NOW=max(1,NOW-1)
        ANS+=1
    else:
        if A[i]>=NOW-1:
            ANS+=1
            NOW=max(NOW-1,1)
        else:
            ANS+=max(1,NOW-A[i])
            NOW=A[i]
    i+=1
    #print(i,ANS,NOW)

ANS+=(NOW-1)
print(sum(A)-ANS)


#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    #a=list(map(int,sys.stdin.readline().split(' ')))
    n,k= list(map(int, sys.stdin.readline().split(' ')))
    a=list(map(int,sys.stdin.readline().split(' ')))
    a.sort()

    ans=0
    c=1

    for i in range(n):
    	if(c>a[n-1] or c>a[i]):
    		ans+=a[i]-1
    		continue
    	if(i!=n-1):
    		ans+=a[i]-1
    		c+=1
    	else:
    		ans+=c-1
    print(ans)


    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()


n, m = [int(x) for x in input().split()]

a = [int(x) for x in input().split()]

a.sort()
last = 0
total = 0
for i in range(n - 1):
    if a[i]>0 :
        total += a[i] - 1
        last = min(last + 1, a[i])

print(total + max(a[n-1] - max(1, a[n - 1] - last), 0))

n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
s=sum(a)
need=0
a.sort()
j=1
flag=0
k=max(a)
if n==1:
    print(0)
else:
    for i in range(n):
        if a[i]<j:
            flag=1
        else:
            flag=0
        if a[i]==1:
            need+=1
        elif a[i]>=j and i!=n-1:
            need+=1
        elif a[i]>=j and i==n-1 and j<=k:
            need+=k-j+1
        else:
            need+=1
        if flag!=1:
            j+=1
    print(s-need)
        
        


n,m=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
ans=0
height=0
for i in range(n):
    if(arr[i]>height):
        ans+=1
        height+=1
    else:
        ans+=1

if(arr[-1]>height):
    ans+=(arr[-1]-height)
print(sum(arr)-ans)

a,b = map(int,input().split())
list1 = [*map(int,input().split())]
list1.sort(reverse= True)
ans = 0
neededHeight = list1[0]
for i,j in enumerate(list1[1:]):
	neededHeight = max(min(j, list1[i]-1),1)
	ans += j-neededHeight
	if list1[i]>1:
		ans+= neededHeight
	list1[i+1] = neededHeight
print(ans)

n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
if n==1:
	print(0)
	return
ans = 0
a.sort(reverse=True)
p=a[0]
for j in range(n-1):
	#k=a[j]-a[j+1]
	if p<=0:
		ans+=a[j]-1
		continue
	if a[j+1]>=p-1:
		ans+=a[j]-1
		p-=1
	else:
		k=p-a[j+1]
		ans+=a[j]-k
		p-=k
	
	#p=a[j+1]
	#print(ans,p)
if p<0:
	p=0
ans+=a[-1]-max(p,1)
print(ans)


#a = [int(i) for i in input().split()]
#n = input()
n,m = map(int,input().split())
a = sorted([int(i) for i in input().split()])
ans = 0

c = a[n-1]
if n==1:
	print(0)
	raise SystemExit



for i in range(n-1,-1,-1):
	if i>0 and a[i-1]<c-1:
		a[i] -= (c-1)-a[i-1]
		ans += a[i]-1
		c = a[i-1]
	else:
		if a[i]>=c:
			ans+=a[i]-c
			if i:
				ans+=max(c-1,0)
			c-=1
	c = max(c,1)


print(ans)

n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
l.sort()
c=max(l)
low=0
ans=0
for i in range(n-1):
    if l[i]>low:
        ans+=l[i]-1
        low+=1
    else:
        ans+=l[i]-1
if low==c:
    ans+=low-1
else:
    ans+=low
print(ans)