DNA samples from thousands of years ago show the Ancient Greeks descended from two even more distant peoples, solving a genetic mystery that had scientists scratching their heads for years.

Although the Greeks are a famous ancient civilization, they were following in the footsteps of two other groups known as the Minoans and the Mycenaeans who lived around the Aegean Sea, the embayment in the northeastern Mediterranean that today is surrounded by Greece and Turkey. But not much is known about those two predecessors, in terms of where their people originated and how they came to inhabit mainland Greece and the island of Crete during the Bronze Age. A recent genetic analysis, however, gives scientists some insight: The Minoans and the Mycenaeans were closely related to one another, with similar but not identical DNA, and modern Greeks are descended from them.

Read: DNA From Ancient Mammoth Hunters Makes This Country’s Men the Tallest in the World

The study, published in the journal Nature, relied on the DNA from the teeth of 19 ancient people who belonged to the Minoan and Mycenaean cultures as well as to the lands of southwestern Anatolia — modern day Turkey, just across the Aegean Sea from Greece. Their genes were compared to those of hundreds of other ancient people.

“We show that Minoans and Mycenaeans were genetically similar, having at least three-quarters of their ancestry from the first Neolithic farmers of western Anatolia and the Aegean, and most of the remainder from ancient populations related to those of the Caucasus and Iran,” the study says. “However, the Mycenaeans differed from Minoans in deriving additional ancestry from an ultimate source related to the hunter–gatherers of eastern Europe and Siberia.”

The DNA from the Caucasus suggests migration of peoples from that area toward the Aegean after the time of those early Stone Age farmers.

Comparing the ancient DNA to more than 2,600 samples from modern Greeks proves the current population is close to the Mycenaeans genetically, but also has DNA from other early Stone Age ancestors.

According to the researchers, the DNA results show that although more people migrated to the area and introduced additional genetic material, there has been a long-running genetic continuity in what is now Greece, giving modern-day inhabitants an idea of their connection to the land even further back than the ancient Greek civilization that was the birthplace of democracy, philosophy and the Olympics.

After migrating thousands of years earlier from Anatolia, the Minoan civilization appears to have formed first on Crete about 5,000 years ago, but shared time and space with the Mycenaeans on the mainland during the Bronze Age before disappearing about 3,000 years ago.

Read: Ancient Egyptians Were More Asian Than African, DNA Shows

The University of Washington explained that the Minoans and Mycenaeans, which had similar cultures, were much more advanced than some people would imagine: “The Minoans were also the first literate people of Europe,” the university said, and the Mycenaeans used an early form of written Greek when they emerged a thousand years into the Minoan reign.

“While the new study does not resolve all the outstanding questions, it provides key answers,” according to the university. “Importantly, the findings disprove the widely held theory that the Mycenaeans were a foreign population in the Aegean and were not related to the Minoans. The results also dispel the theory that modern Greeks did not descend from the Mycenaeans and later ancient Greek populations.”