def main():
  e,M=enumerate,10**9+7
  n,k,*a=map(int,open(0).read().split())
  dp=[[0]*(k+1)for _ in range(n+1)]
  dp[0][0]=1
  for b,d,a in zip(dp,dp[1:],a):
    a+=1
    t=0
    for j,v in e(b[:a]):
      t+=v
      t%=M
      d[j]=t
    for j,(w,v)in e(zip(b,b[a:]),a):
      t+=v-w
      t%=M
      d[j]=t
  print(t)
main()