h,n=map(int,input().split()) r=sorted([-h]+[-int(input())for _ in range(n-1)]).index(-h) f=lambda x:r%10