diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -22,7 +22,7 @@
     B.append(A[i])
 B.sort()
 
-for i in range(n - 2 - m):
+for i in range(n - 2 - m + 1):
     val = max(amin - B[i], 0) + max(B[i + m - 1] - amax, 0)
     if an > val:
         an = val
