#include <bits/stdc++.h>
using namespace std;
const int N = 2005, M = (int)1e9 + 7;
int a[N], n, h;
long long F[N];
void init() {
  F[0] = 1;
  for (int i = 1; i < N; i++) F[i] = F[i - 1] * i % M;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> h;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] > h) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (a[1] <= h - 2 || a[n] <= h - 2) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] - a[i - 1] <= -2 || a[i] - a[i - 1] >= 2) {
      cout << 0 << endl;
      return 0;
    }
  }
  a[0] = a[n + 1] = h;
  stack<int> S, s;
  long long ans = 1;
  int tmp;
  s.push(0);
  for (int i = 1; i <= n + 1; i++) {
    if (a[i] == a[i - 1] - 1) {
      S.push(i);
      s.push(s.top() + 1);
    } else if (a[i] == a[i - 1] + 1) {
      ans *= s.top();
      ans %= M;
      s.pop();
      S.pop();
    }
  }
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i + 1]) {
      ans *= (h - a[i] + 1);
      ans %= M;
    }
  }
  cout << ans << endl;
  return 0;
}
