By default, builds are versioned with date and revision: $(Date:yyyyMMdd).$(Rev:r), eg. 20200507.42. The date changes every day (obviously), and for each day revision will start counting from 1: 20200101.1, 20200101.2, 20200102.1, and so on.
$(Rev:r) will look for internal (inaccessible by users) build versions collection, increment last version number and return it.
If you would like to start numbering your packages from value other than 1, use $[counter(variables['system.collectionId'], 340)]. It'll create a new sequence named by your repository ID, starting from given value (`340`) and it'll increment itself on each invocation. Note that if you have multiple pipelines, they all will share the same sequence.
There is a task in market which will retrieve last version number from Build_BuildId variable. See GetRevision task.