<P> Latvian, German and Estonian ministers sign non-aggression treaties, 1939 </P> <P> The Soviet Union guaranteed its interests in the Baltics with the signing of the Molotov--Ribbentrop Pact between the Soviet Union and Nazi Germany on August 23, 1939 . Under threat of invasion, Latvia (along with Estonia and Lithuania) signed the Soviet--Latvian Mutual Assistance Treaty with Soviet Union, providing for the stationing of up to 25,000 Soviet troops on Latvian soil . Following the initiative from Nazi Germany, Latvia on October 30, 1939 concluded an agreement to "repatriate" ethnic Germans, most of whom had lived in the region for generations, in the wake of the impending Soviet takeover . </P> <P> Seven months later, the Soviet foreign minister Vyacheslav Molotov accused the Baltic states of conspiracy against the Soviet Union . On June 16, 1940, threatening an invasion, Soviet Union issued an ultimatum demanding that the government be replaced and that an unlimited number of Soviet troops be admitted . Knowing that the Red Army had entered Lithuania a day before, that its troops were massed along the eastern border and mindful of the Soviet military bases in Western Latvia, the government acceded to the demands, and Soviet troops occupied the country on June 17 . Staged elections were held July 14--15, 1940, whose results were announced in Moscow 12 hours before the polls closed; Soviet documents show the election results were forged . The newly elected "People's Assembly" declared Latvia a Socialist Soviet Republic and applied for admission into the Soviet Union on July 21 . Latvia was incorporated into the Soviet Union on August 5, 1940 . Latvian diplomatic service continued to function in exile while the republic was under the Soviet control . </P> <P> In the spring of 1941, the Soviet central government began planning the mass deportation of anti-Soviet elements from the occupied Baltic states . In preparation, General Ivan Serov, Deputy People's Commissar of Public Security of the Soviet Union, signed the Serov Instructions, "Regarding the Procedure for Carrying out the Deportation of Anti-Soviet Elements from Lithuania, Latvia, and Estonia ." During the night of 13--14 June 1941, 15,424 inhabitants of Latvia--including 1,771 Jews and 742 ethnic Russians--were deported to camps and special settlements, mostly in Siberia . 35,000 people were deported in the first year of Soviet occupation (131,500 across the Baltics). </P>

When did latvia became part of the soviet union