A finite dam is studied in which the net input in each period, i.e. the excess of input over demand, is a function of a Markov chain. By using a martingale, the joint distribution of the time to first overflow and the cumulative unsatisfied demand until overflow is investigated. The probability of overflow before the unsatisfied demand exceeds a fixed level is also considered.