Only time on a residence permit counts, and it must be continuous. A student stay does not count, because Spanish law treats it as a stay rather than residence.