PAM algorythm complete