You can fetch the existing count on dialog load. On dialog submission, fetch the newly authored count. If it's lower than the previous value, run a loop for the difference to add the below input elements:
<input class="foundation-field-related" type="hidden" name="./container/row{count}@Delete">
...