Compute offset as MAX(num) instead of COUNT(num).

This is needed as an history stack may not have continuous num values. This
can happen after applying a style or a partial copy/paste.