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stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
inline long long read() {
  long long res = 0;
  char c;
  bool flag = true;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') flag = false;
    c = getchar();
  }
  while (isdigit(c)) {
    res = res * 10 + (c ^ 48);
    c = getchar();
  }
  return flag ? res : -res;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar('0' + x % 10);
}
const long long Max_n = 505;
long long ls[Max_n << 2], rs[Max_n << 2], n, h[Max_n], logm[Max_n], nee,
    jc[Max_n], tot, f[Max_n << 2][Max_n], len[Max_n << 2];
struct node {
  long long hei, pos;
  node(long long a, long long b) { hei = a, pos = b; }
  node() {}
  bool operator<(const node& a) const { return hei < a.hei; }
} minn[Max_n << 2][20];
inline void build() {
  for (long long i = 1; i <= n; ++i) minn[i][0] = node(h[i], i);
  for (long long j = 1; j <= logm[n]; ++j)
    for (long long i = 1; i <= n; ++i)
      minn[i][j] = min(minn[i][j - 1], minn[i + (1 << (j - 1))][j - 1]);
}
inline long long find(long long l, long long r) {
  if (l > r) swap(l, r);
  long long len = r - l + 1;
  return min(minn[l][logm[len]], minn[r - (1 << logm[len]) + 1][logm[len]]).pos;
}
inline long long quickpow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret *= x, ret %= MOD;
    x *= x, x %= MOD;
    y >>= 1;
  }
  return ret;
}
inline long long ni(long long x) { return quickpow(x, MOD - 2); }
inline long long C(long long n, long long m) {
  if (n < m) return 0;
  return jc[n] * ni((jc[n - m] * jc[m]) % MOD) % MOD;
}
inline long long calc(long long l, long long r, long long k) {
  long long ret = 1;
  ret *= C(l, k), ret %= MOD;
  ret *= C(r, k), ret %= MOD;
  ret *= jc[k], ret %= MOD;
  return ret;
}
void dfs(long long l, long long r, long long tall, long long& tr) {
  tr = ++tot;
  if (l > r) {
    len[tr] = 0;
    f[tr][0] = 1;
    return;
  }
  if (l == r) {
    len[tr] = 1;
    f[tr][1] = h[l] - tall;
    f[tr][0] = 1;
    return;
  }
  len[tr] = r - l + 1;
  long long mid = find(l, r);
  dfs(l, mid - 1, h[mid], ls[tr]);
  dfs(mid + 1, r, h[mid], rs[tr]);
  for (long long j = 0; j <= min(len[ls[tr]], nee); ++j)
    for (long long k = 0; k <= min(len[rs[tr]], nee); ++k)
      f[tr][j + k] += f[ls[tr]][j] * f[rs[tr]][k] % MOD, f[tr][j + k] %= MOD;
  for (long long i = min(r - l + 1, nee); i >= 0; --i)
    for (long long j = 0; j < i; ++j)
      f[tr][i] += f[tr][j] * calc(h[mid] - tall, r - l + 1 - j, i - j) % MOD;
}
signed main() {
  n = read(), nee = read();
  jc[0] = 1;
  for (long long i = 1; i <= 500; ++i) jc[i] = jc[i - 1] * i % MOD;
  for (long long i = 2; i <= n; ++i) logm[i] = logm[i / 2] + 1;
  for (long long i = 1; i <= n; ++i) h[i] = read();
  build();
  dfs(1, n, (long long)0, ls[0]);
  write(f[1][nee]);
  return 0;
}
