<?php
  fscanf(STDIN, "%d %d", $n, $m);
  $numbers = trim(fgets(STDIN));
  $breakSt = explode(" ", $numbers);
  $ans = 2;
  $sum = 0;
  for($i = 0;$i < $n; $i++){
    $sum += $i;
  }
  $max = $sum;
  for($i = 0;$i < $n; $i+=2){
    $sum += $i;
  }
  $min = $sum;
  while($sum != $min){
    $step = 0;
    $sum = 0;
    for($i = 0;$i < $n; $i++){
      $step++;
      $sum += $n;
      if($sum == $max){
        $step--;
      }
      if($step == $breakSt){
        $step++;
      }
      if($sum = $min){
        break;
      }
    }
    $ans++;
  }
  echo $ans % 10000000007;
  ?>