import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BjSolution sol = new BjSolution();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] inputs = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int row = inputs[0];
int col = inputs[1];
int[] heightArr = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
sol.solve(row, col, heightArr);
}
}
class BjSolution {
public void solve(int row, int col, int[] heightArr) {
int answer = 0;
int[][] map = new int[row][col];
int cIdx = 0;
for (int height : heightArr) {
int rIdx = row - 1;
for (int count = 0; count < height; count++) {
map[rIdx][cIdx] = 1;
rIdx--;
}
cIdx++;
}
for (int r = 0; r < row; r++) {
boolean isLeftWallClosed = false;
int tempSaveWater = 0;
for (int c = 0; c < col; c++) {
if (isWall(map, r, c)) {
if (isLeftWallClosed) {
answer += tempSaveWater;
tempSaveWater = 0;
}
isLeftWallClosed = true;
} else {
if (isLeftWallClosed) {
tempSaveWater++;
}
}
}
}
System.out.println(answer);
}
private boolean isWall(final int[][] map, final int r, final int c) {
return map[r][c] == 1;
}
}