```
class Solution(object):
def findCircleNum(self, M):
"""
:type M: List[List[int]]
:rtype: int
"""
count = len(M)
students = [i for i in xrange(len(M))]
for i, row in enumerate(M):
for j, column in enumerate(row):
if column == 1 and students[i] != students[j] and i != j:
count -= 1
tmp_i = students[i]
for k, student in enumerate(students):
if student == tmp_i:
students[k] = students[j]
return count
```