If you were buying a car, would your first step be to walk into a dealer's showroom? Or to apply with your credit union or bank? Of course not. Your first step would be to decide what sort of car you were looking for--a sedan, an SUV, etc. How many people should it be able to transport (large family? just you?). In other words, you'd figure out what you needed and wanted.
If you were going on a vacation, would your first step be to walk into the airport to buy a ticket? Of course not. Your first step would be to decide where you wanted to go. Beach or mountains? United States or overseas? Active or relaxing vacation? A quick 3-day getaway or a longer 2-week vacation? After you'd narrowed it down a bit, then you might do some research--online, or go into a travel agent, etc.
So your first step in buying a house should not be either of the two steps you're considering. It ought to be figuring out what you want. General location. Size. Any particular features you want. Anything you really don't want. Urban, suburban, or rural? And so on. Now, it's true that what you want may not be what you can afford. Just as someone might want a 2-week vacation , but only can afford a 1-week vacation. But that's OK. You need to start somewhere.
Besides, the first question a Realtor will ask might be: "What are you looking for?" You might as well have thought it through first.
So, once you've made a list of what you want and what you don't want, do you then find a Realtor or a lender? My personal suggestion would be: a Realtor, who (based on your needs and interests) probably can refer you to one that can best help you. But, as you can see from the answers here, a good case can also be made for finding a lender first.
In either case though, the first step is determining what you want. Then come the Realtor and the lender.
Hope that helps.