On September 10th, 1963, John and Paul visited the Rolling Stones while they were rehearsing in the studio - and wound up writing "I Wanna Be Your Man" whilst they were there. The song features on With The Beatles, but the band also gave it to the Stones, who recorded it a month later and released it on November 1st, that year.
"Mick Jagger and Keith Richards would later credit being able to watch Lennon and McCartney that day with giving them a greater understanding of how to write a song." (- Ultimate Classic Rock)
You can read more about how The Beatles ended up writing for the Stones in this article.