First itersation of melody algorithm