#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
int a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int t = *max_element(a + 1, a + n + 1),
      s = max_element(a + 1, a + n + 1) - &a[0];
  int sum = 0;
  if (t == 1) {
    for (int i = 2; i <= n; i++) sum += 5 - a[i];
    cout << sum;
    return 0;
  }
  for (int i = 1; i <= t - 1; i++) {
    if (a[i - 1] > a[i]) sum += a[i - 1] - a[i];
  }
  for (int i = t; i <= n; i++) {
    if (t > a[i]) sum += t - a[i];
  }
  cout << sum;
}
