#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d%d*[^\n]", &n, &m);
  scanf("%*c");
  std::vector<int> broken_stair(m);
  for (size_t i = 0; i < m; i++) {
    if (scanf("%d%*[^\n]", &broken_stair.at(i)) != 1) {
      return 1;
    }
    scanf("%*c");
    if (i > 0 && broken_stair.at(i) - broken_stair.at(i - 1) < 2) {
      printf("%d\n", 0);
      exit(1);
    }
  }
  return 0;
}
