First solution for grains exercise