#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(m + 1, 0), b(m, 0);
  for (long long i = 0; i < (m); i++) cin >> a[i];
  for (long long i = 0; i < (m - 1); i++) {
    if (a[i + 1] - a[i] <= 1) {
      cout << 0 << endl;
      return 0;
    }
    b[i] = a[i + 1] - a[i] - 2;
  }
  return 0;
}
