My advice would be to buy the medium, especially if the bikes you're looking at buying are 29ers. Your height and inseam place you the upper range for size medium, however you need to grow 2½-4cm to place you at the low range of the large size. In addition many 19" MTB 29ers have stand-over heights (distance from the ground to the top of the middle of the top tube--basically where you would be if you stopped the bike, got off the seat and stood on the ground straddling the bike) between 31 & 32 inches. Conventional wisdom of bike fitting says you should have 1-2 inches clearance between the top tube and your crotch when standing flat footed on the ground. Your inseam calculates out to 31 inches.
Now all that being said, the absolute key to this is how you feel--your comfort--when riding a particular bike. There is such a wide range of choices of bikes and the geometries of these vary quite a bit as well. Thus, a bike that is sized medium whose geometry is race oriented and more "slack" and with a top tube that is highly angled may feel too small for a person with your dimensions while a more city or trail oriented frame that sets you more upright and is also a size medium may perhaps feel just right. The point is that all these numbers and calculations and conventional wisdom of proper bike fit mean absolutely nothing if the bike doesn't feel good to ride. I suggest borrowing a friend's bike for a few hours to a day, if possible, and ride it and see how it feels. Note the frame size and the general class of mountain bike (XC, trail, all-mountain/enduro, and downhill) if the particular bike classifies itself. Ride and see how it feels. Then ride another bike that maybe differs in size and/or geometry to see how that feels. At this point it's possible to either eliminate a size or style or note a few aspects to further experiment with. Keep in mind, that one bike can have a wide range of set-up options from tire and rim choice to seat height and front-back difference, handle bar, suspension travel, etc which will offer a little variation of one bike's fit. So at this stage you're somewhat feeling out and creating a pool of possible candidates.
A third aspect of choosing a bike is determining where and how the bike is ridden. There are better choices for a bike that is to be ridden in mostly urban areas of pavement and groomed trails compared to a bike that will be ridden in unpaved mountainous terrain and bike parks featuring wild single track. You needn't be too focused on getting this absolutely right either since a general use mountain bike can be set up to handle a very wide range of terrain and conditions. And while a road bike with narrow tire pressured to a 100psi would be a damn poor choice, it will roll right down the mountain trail just as a slacked out full-suspension mountain bike will. Gravity works. On one, you're likely be miserable and feel out of place and on the other the ride will feel like you're one with the mountain. Choosing the right bike for your typical riding conditions and style is an aspect of a bike purchase but think of it as selecting something "more right" than needing it to be perfect.
Here's my concrete opinion with the given facts of the question: You should look to the pool of medium sized, hardtail, XC or trail bikes offered by a quality maker (Specialized, Trek, GT, Santa Cruz, Cannondale, Pivot, Canyon, and others). Basically, the brands of bike that are sold through true bike shops. Avoid department store bikes as the diminished quality and substantial weight of these types of bikes detract from the joy of riding, are sometimes poorly or incorrectly built up, and these types of stores lack knowledgeable support specific to bikes and bicycling. The bike you choose should be aluminum frame because you can get more for your money compared to a more expensive base of carbon fiber. Travel of the front fork suspension should be 120mm or more. Air forks are lighter and more tunable but coil forks have their place. It's most important to have the sag and rebound set-up correctly for your riding weight. Pricing of a new, good quality, aluminum, entry-level hardtail MTB can be $1000-1500 at the time of this writing. Less than this you begin to run into manufacturers using inferior components--especially brakes and suspension forks--to shave cost. If your budget doesn't permit such an expenditure, look to the used bike market where a five year old bike can bought for several hundred dollars less while maintaining (sometimes even exceeding) the quality of componentry of a new bike. The latest tweaks to modern geometry will be absent, but at the entry level it's questionable such changes have any meaningful effect. Certainly won't be any night and day difference to a beginner.
Here's a few good references via a Google search of "buying a first mountain bike."
Outside Online-Buying Your First Mountain Bike
DIY Mountain Bike
MTBer.com 5 Things You Need to Know