You put an S after the N instead of a $, so it is taking all of those lines beginning there as integer values. You cannot compare a integer to a string, so therefore an error occurs at the first line where that happened. To fix this just change all of the NS's to N$.
You didn't finish the line 39's IF statement. If you don't finish an IF statement, a FOR loop, or a WHILE loop, it will tell you not on the line that the error is, but rather the line where it realizes that it cannot be finished later. So just finish that IF statement and you should be good.