using greedy type alg for max filter