```python
def parse_duration(text: str) -> int:
    if not text:
        raise ValueError("Input string cannot be empty")
    
    units = {'d': 86400, 'h': 3600, 'm': 60, 's': 1}
    total_seconds = 0
    i = 0
    
    while i < len(text):
        if text[i].isdigit():
            value_start = i
            while i + 1 < len(text) and text[i + 1].isdigit():
                i += 1
            value = int(text[value_start:i + 1])
            
            if i + 1 >= len(text) or text[i + 1] not in units:
                raise ValueError("Missing unit after value")
            
            unit = text[i + 1]
            i += 2
            
            if unit not in units:
                raise ValueError(f"Unknown unit: {unit}")
            
            total_seconds += value * units[unit]
        else:
            raise ValueError("Invalid character in input string")
    
    return total_seconds
```