Plan repair is the problem of solving a given planning problem by using a solution plan of a similar problem. Plan repair problems can arise in execution contexts, that is, when an agent performing the plan has to deal with some unexpected contingency that makes the given plan invalid. Repairing a plan works often much better than replanning from scratch, and is crucial when plans have to be kept stable. There is no planning system until now that guarantees to find plans at the minimum distance from an input plan. This paper presents the first approach to such a problem; we indeed introduce a simple compilation scheme that converts a classical planning problem into another where optimal plans correspond to plans with the minimum distance from an input plan. Our experiments using a number of planners show that such a simple approach can solve the plan repair problem optimally and more effectively than replanning from scratch for a large number of cases. Last but not least, the approach proves competitive with LPG-ADAPT.