#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int d, n;
  cin >> d >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int day = 0, res = 0;
  for (int i = 0; i < n; i++) {
    day = (day + a[i] - 1) % d + 1;
    if (day != a[i]) {
      if (day < a[i])
        res += a[i] - day;
      else
        res += d - day + a[i];
      day = a[i];
    }
  }
  cout << res;
}
