function Main(input) {
  input = input.split("\n");
  input[0] = input[0].split(" ");
  input[1] = input[1].split(" ");
  var N=parseInt(input[0][0]);
  var M=parseInt(input[0][1]);
  var path=Math.max(M-N,0);
  if(path===0){
    console.log(0);
    return;
  }
  (function(){for(var i=0;i<M;i++){
    input[1][i]=parseInt(input[1][i]);
  }})();
  var Xs=input[1];
 
  var x_axis=[];
  var delta=[];
  (function(){for(var j=0;j<200001;j++){
    x_axis[j]=0;
    delta[j]=0;
  }})();
  (function(){for(var k=0;k<M;k++){
    x_axis[Xs[k]+100000]++;
  }})();
  (function(){
    var counter=0;
    for(var i=0;i<200001;i++){
      if(x_axis[i]===0)counter++;
      else{
        delta[counter+1]++;
        counter=0;
      }
    }
  })();
  (function(){
    var counter=0;
    var deltax=0;
    for(var i=0;i<path;deltax++){
      if(delta[deltax]===0) continue;
      i++;
      delta[deltax]--;
      counter+=deltax;      
      deltax=0;
    }
    console.log(counter);
  })();  

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));