------
## 最终结论
```python
def minKBitFlips(A, K):
    flip_count = 0
    is_flipped = [0] * len(A)
    flip = 0
    
    for i in range(len(A)):
        if i >= K:
            flip ^= is_flipped[i - K]
        
        if (A[i] + flip) % 2 == 0:
            if i + K > len(A):
                return -1
            flip_count += 1
            flip ^= 1
            is_flipped[i] = 1
    
    return flip_count

# Example usage:
# A = [0,1,0], K = 1
# Output: 2
print(minKBitFlips([0,1,0], 1))

# A = [1,1,0], K = 2
# Output: -1
print(minKBitFlips([1,1,0], 2))

# A = [0,0,0,1,0,1,1,0], K = 3
# Output: 3
print(minKBitFlips([0,0,0,1,0,1,1,0], 3))
```