#!/usr/bin/env python # -*- coding: utf-8 -*- N,M = map(int,input().split()) C = sorted(list(map(int,input().split()))) i = 0 while M >= 0: M -= 1 while C[i] == 0: i+= 1 if i >= N: N = 0 C[i] -= 1 print(sum([1 if C[i] <= 0 else 0 for i in range(N)]))