start writing pam algorithm