n,d = gets.split(' ').map(&:to_i)
x = []
n.times do |a|
        nums = gets.split(' ').map(&:to_i)
        x << nums
end
count = 0
(0..n-1).each do |a|
    sum = 0
    (0..d-1).each do |b|
        dis = (x[a-1][b]-x[a][b])**2
        sum = sum + dis
    end
    if Math.sqrt(sum).ceil == Math.sqrt(sum)
        count += 1
    end
end
puts count
