read n m read -aa for((;m--;v=a[m],r>1?r-=v>=r:(r=v))){ : } echo $r