int getLastCommandTimestamp(@NotNull DocumentReference r) {
    UndoRedoList<UndoableGroup> stack = getStack(r);
    if (stack.isEmpty()) return 0;
    return Math.max(stack.getFirst().getCommandTimestamp(), stack.getLast().getCommandTimestamp());
  }
int getLastCommandTimestamp(@NotNull DocumentReference r)