h, w = gets.chomp.split.map(&:to_i)
map = []
h.times{map << gets.chomp}
arr = Array.new(h+1){Array.new(w+1){[0,0]}}

sum = 0
(h-1).downto(0){|j|
    (w-1).downto(0){|i|
        arr[j][i][0] = arr[j][i+1][0]
        arr[j][i][1] = arr[j+1][i][1]
        case map[j][i]
        when "J"
            sum += arr[j][i][0] * arr[j][i][1]
        when "O"
            arr[j][i][0] += 1
        when "I"
            arr[j][i][1] += 1
        end
    }
}
puts sum
