exactly. How this happened is the pond slime in a certain area was under the influence of some stong wind forces. One day, a strong gust came up and raised some of the slime into the air. It didn't fly for long before it landed on the shore, but it determined that it enjoyed flight somehow. Though the slime did not yet have a brain there was a code embedded in the dna that it needed to later grow wings and fly.
Listen... its all very complex and i dont have all day to describe what happened over 38.65 million years of evolution, but the point is- Thats what happened.