Cook the potatoes in a large saucepan of boiling water for about 10 minutes until just tender. Drain and leave until cool enough to handle, then remove the skins and slice into 5 mm (¼ inch) slices.
Heat the oil in a large saucepan, add the onion and garlic and cook gently for 3–4 minutes until softened. Add the carrot, cinnamon and herbs, then stir in the tomatoes, kidney beans and stock. Season to taste with salt and pepper and bring to the boil, then reduce the heat and simmer, uncovered, for 15 minutes until thickened.
Meanwhile, make the sauce. Place the butter, flour and milk in a saucepan and whisk constantly over a medium heat until the sauce boils and thickens. Simmer for 2–3 minutes until you have a smooth glossy sauce. Stir in the cheese and then remove from the heat. Leave to cool slightly, then beat in the egg.
Place half the bean mixture in the bottom of a deep ovenproof dish and top with a layer of potatoes. Repeat, finishing with a layer of potatoes. Pour over the sauce and bake in a preheated oven, 180°C (350°F), Gas Mark 4, for 25–30 minutes until golden brown. Leave to stand for 5 minutes before serving.