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