5315 FOR Z=1 TO KM