#include <bits/stdc++.h>
using namespace std;
int main() {
  long long mod = 1000000007;
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  long long ans;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    ans = ((long long)pow(2, a[0] - 1)) % mod;
  }
  for (int i = 0; i < (n - 1); i++) {
    if (a[i + 1] == a[i] + 1) {
      cout << 0 << endl;
      return 0;
    }
    ans *= ((long long)pow(2, a[i + 1] - a[i] - 2)) % mod;
  }
  cout << ans << endl;
  return 0;
}
