#include <bits/stdc++.h>
using namespace std;
int sumarraybegin(vector<int> &w, int j, int n) {
  int sum = 0;
  for (int i = j; i < n; i++) {
    sum++;
  }
  return sum - 1;
}
int main() {
  int n, m;
  int step1 = 1;
  int step2 = 2;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
  }
  vector<int> k(m + 1);
  long long ans = 1;
  int j = 0;
  for (int i = 0; i < n; i++) {
    k.at(i) = sumarraybegin(a, j, a.at(i));
    j = a.at(i);
  }
  for (int i = 0; i < k.size(); i++) {
    ans *= k.at(i);
  }
  cout << ans % 1000000007 << endl;
}
