'use strict'
function main(input) {
  input = input.trim().split('\n')
  const NM = input.shift().split(' ').map(v => Number(v))
  input = [0, ...input.map(v => Number(v)), NM[0]]

  const calc = d => {
    return d < 2 ? 1 : (d - 1) * (d - 2) / 2 + 2
  }
  let ans = 1
  
  for (let m = 1; m <= NM[1] + 1; m++) {
    let diff = input[m] - input[m - 1] - 1
    if (diff === 0 && m!==1) {
      console.log(0)
      return
    }
    ans = ans * (calc(diff))
  }
  console.log(ans % 1000000007)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
