n, m = map(int, input().split())
l = []
for _ in range(n):
    l.extend(list(map(int, input().split())))
l.append(0)
l.sort()
print(sum(l[l.index(0):]))