var main = (Input) => {
    var input = Input.split("\n");
	var tmp = input[0].split(" ");
	var n = Number.parseInt(tmp[0]);
    var d = Number.parseInt(tmp[1]);
  	var count = 0;
  
  	for (var i = 0 ; i < n; i++){
      if (i === n-1) {
      	var arr1 = Number.parseInt(input[i+2].split(""));
        var arr2 = Number.parseInt(input[1].split(""));
      }
    	var arr1  = Number.parseInt(input[i+1].split("")); 
        var arr2 = Number.parseInt(input[i+2].split(""));
      	var sum = 0;
      for (var j=0; j < d; j++){
        var sq = (arr1[j]-arr2[j])*(arr1[j]-arr2[j]);
        sum = sum + sq;
      }
      if (Number.isInteger(Math.sqrt(sum))) count++;
    }
  
  console.log(count);
    	
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));