import sys
n,m = map(int, input().split())
first = input()
agcts = [list(first)]
for i in range(n-1):
now = list(input())
# 선발된 염기서열 하나씩 비교
for agct in agcts:
same = True
# 염기서열 한 자리 씩 비교
for j in range(m):
if now[j] != agct[j] and now[j] != "." and agct[j] != "." :
same = False
if same :
for k in range(m):
if agct[k] == "." and now[k] != ".":
agct[k] = now[k]
break
else:
agcts.append(now)
print(len(agcts))