```python
def check_digit(code: str) -> int:
    if not code.isdigit():
        raise ValueError("Code must contain only digits")

    total = sum(int(digit) for digit in code)
    return (total + 9) % 10
```