#include <bits/stdc++.h>
using namespace std;
const int maxn = 2345;
const int MOD = 1e9 + 7;
int n, m, ai[maxn];
void init() {
  for (int i = 1; i <= n; i++) scanf("%d", &ai[i]);
  for (int i = 1; i <= n; i++) ai[i] = m - ai[i];
}
void DYGANDQYM() {
  ai[0] = 0;
  ai[n + 1] = 0;
  long long ans = 1;
  for (int i = 1; i <= n + 1; i++) {
    if (ai[i] == ai[i - 1] + 1) continue;
    if (ai[i] == ai[i - 1] || ai[i] == ai[i - 1] - 1)
      ans = (ans * (ai[i] + 1)) % MOD;
    else {
      printf("0\n");
      return;
    }
  }
  printf("%I64d\n", ans);
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    init();
    DYGANDQYM();
  }
  return 0;
}
