------
## 最终结论
```python
def min_subarray_length(nums, p):
    total_sum = sum(nums)
    total_remainder = total_sum % p

    if total_remainder == 0:
        return 0

    prefix_sums = {}
    min_length = float('inf')
    current_prefix_sum = 0

    for i in range(len(nums)):
        current_prefix_sum += nums[i]
        current_prefix_sum %= p
        
        if current_prefix_sum == total_remainder:
            min_length = min(min_length, i + 1)

        target_remainder = (current_prefix_sum - total_remainder) % p
        
        if target_remainder in prefix_sums:
            min_length = min(min_length, i - prefix_sums[target_remainder])
        
        prefix_sums[current_prefix_sum] = i

    return min_length if min_length != float('inf') else -1
```