#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10, mod = 1e9 + 7;
int long long n, mn[maxn], dp[maxn], h;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> h;
  for (int i = 1; i <= n; i++) {
    cin >> mn[i];
    mn[i] = h - mn[i];
  }
  for (int long long i = 1; i <= n; i++)
    if (min(i - 1, n - i) < mn[i] - 1 || abs(mn[i] - mn[i - 1]) > 1 ||
        abs(mn[i] - mn[i + 1]) > 1)
      return cout << 0, 0;
  dp[1] = 1;
  for (int i = 2; i <= n + 1; i++)
    if (mn[i - 1] < mn[i])
      dp[i] = dp[i - 1];
    else if (mn[i - 1] > mn[i])
      dp[i] = (dp[i - 1] * mn[i - 1]) % mod;
    else {
      dp[i] = (dp[i - 1] * mn[i]) % mod;
      dp[i] += dp[i - 1];
      dp[i] %= mod;
    }
  cout << dp[n + 1];
}
