n, m = read_line.split.map &.to_i64 c = read_line.split.map &.to_i64.pred sizes = c.tally graph = Array.new(n) { |color| Array(Array(Int64)).new(sizes[color]? || 0) { [] of Int64 } } hash = Array.new(n) { Hash(Int64, Int32).new } m.times do u, v = read_line.split.map &.to_i64.pred if c[u] == c[v] color = c[u] hash[color][u] = hash[color].size unless hash[color].has_key?(u) hash[color][v] = hash[color].size unless hash[color].has_key?(v) u2 = hash[color][u] v2 = hash[color][v] graph[color][u2] << v2 graph[color][v2] << u2 end end ans = n.times.sum { |color| n_edges = graph[color].sum(&.size.to_i64) // 2 Math.max(0_i64, (sizes.fetch(color, 0_i64).to_i64 - 1) - n_edges) } puts ans