PAM algorythm - dynamic k