package bojenje;

import java.util.Scanner;

public class Bojenje {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int M = input.nextInt();
        int br = 0, br1 = 0, sum = 0;
        String[][] a = new String[N + 1][M + 1];
        int[] b = new int[N];
        for (int i = 0; i < N; i++) {
            b[i] = input.nextInt();
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                a[i][j] = ".";
            }
        }
        for (int j = 0; j < N; j++) {
            for (int i = 0; i < b[j]; i++) {
                if(b[j]<N){
                a[j][i] = "#";
                }
                else if(b[j]>=N){
                a[j][i]=".";
                        
                }
            }
        }
        for (int i = 0; i < N; i++) {
            br = 0;
            br1 = 0;
            for (int j = 0; j < M; j++) {
                if (a[j][i] == ".") {
                    br++;
                } else if (a[j][i] == "#") {
                    br1++;
                }
            }
            sum = sum + br1 * br;
        }
        System.out.print(sum);
    }
}