Input: Sentence: 'Two horses grazing on grass while one of them is behind a fence'. Count the number of nouns in this sentence.
Output: 3