I haven't tested this, but I imagine something like this would work.
$collection = Mage::getModel('catalog/product')->getCollection();
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
foreach($collection as $product) {
$product = Mage::getModel('catalog/product')->load($product->getId());
$entityTypeId = $product->getEntityTypeId();
$mediaGalleryAttribute = Mage::getModel('catalog/resource_eav_attribute')->loadByCode($entityTypeId, 'media_gallery');
$gallery = $product->getMediaGalleryImages();
foreach ($gallery as $image) {
if($image['position'] != "1") {
$mediaGalleryAttribute->getBackend()->removeImage($product, $image->getFile());
}
}
$product->save();
}
What I'm doing here is looping through all of the products and then through their images and removing any that do not have a position of 1.