def main(): import sys input = sys.stdin.read().split() N = int(input[0]) M = int(input[1]) A = list(map(int, input[2:2+N])) sum_A = sum(A) low = 0 high = sum_A // M if M != 0 else 0 # Handle M=0 if needed, but constraints say M≥1 ans = 0 while low <= high: mid = (low + high) // 2 required = mid * M s = 0 possible = True for a in A: available = a + s if available < required: possible = False break s = available - required if possible: ans = mid low = mid + 1 else: high = mid - 1 print(ans) if __name__ == "__main__": main()