```python
def check_digit(code: str) -> int:
    if not code:
        return 0

    total = 0
    for char in code:
        if not char.isdigit():
            raise ValueError("Invalid character in code")
        total += int(char)

    return (10 - (total % 10)) % 10
```