When North Korea decided to go nuclear, it committed to a huge investment in a program that would bring severe sanctions and eat up precious resources that could have been spent boosting the nation's quality of life. Money well spent? Leader Kim Jong Un seems to think so. North Korea's nuclear and missile development programs have without doubt come at a high cost, but the North has managed to march ever closer to having an arsenal capable of attacking targets in the region and — as demonstrated by its July 4 test launch of an intercontinental ballistic missile — the United States' mainland. Good, solid figures for just about anything in North Korea are hard to find. So what follows should be taken as ballpark guesses, at best. But here's a look at how much that arsenal might cost Pyongyang, and why Kim might think that's the price he must pay to survive.

The nuclear pricetag

South Korea has estimated the cost of the North's nuclear program at $1 billion to $3 billion, with the higher number combining nuclear and missile development. For context: one nuclear-powered Virginia class attack submarine costs the United States Navy about $2.5 billion. The USS Gerald Ford, America's newest aircraft carrier, has an $8 billion price tag, not counting development costs.

South Korea's Ministry of National Defense estimated the cost of the first 31 ballistic missiles Kim Jong Un test-launched from when he took power in late 2011 until July last year at $97 million. It put the price of each Scud at $1 million to $2 million; each Musudan from $3 million to $6 million; and each submarine-launched ballistic missile at $5 million to $10 million. Up until July last year, Kim had launched 16 Scuds, six Rodongs, six Musudans and three SLBMs. Including the launch this month of its first ICBM, North Korea has conducted 11 tests, launching 17 missiles, so far this year. North Korea's total defense spending is believed to be around $10 billion a year, or somewhere between a fifth to a quarter of its gross domestic product (about $30 billion to $40 billion).

Where does it get the money?

That's a matter of heated debate. But the $2 billion it made in exports in 2015 would not begin to cover it. North Korea is also believed to have relied on foreign currency sent by tens of thousands of laborers dispatched abroad, as well as exports of illegal weapons and cybercrime. Its military-spending-to-GDP ratio far exceeds any other country, but in monetary terms it spends much less than its neighbors, including South Korea and Japan, and its budget is absolutely minuscule when compared to the United States.

Curtis Melvin, a researcher at the U.S.-Korea Institute at Johns Hopkins University, said that if the South Korean nuclear-program estimate is correct it would be a significant — but not necessarily destabilizing — draw on the North's economy. "This is expensive, but probably a cost the country can absorb without fomenting much resentment among North Korean "elites," he said. "In fact, North Korean elites would probably feel less secure without a nuclear program even if its costs relative to the economy as a whole were higher." Melvin said the economic situation for common North Koreans would have to be in near ruin, with domestic resentment among elites reaching dangerous levels, before North Korea would reconsider its nuclear program. "Current signals indicate that North Korea is nowhere near this breaking point," he said.

Burden or bargain?

The bottom line is that regime survival is Kim Jong Un's primary objective. There is no way North Korea could keep up with its richer and more technologically advanced neighbors in a conventional arms race. While certainly expensive, the North's nuclear strategy is in one sense a potential source of savings — once developed, maintaining a viable nuclear deterrent is less costly than paying for its conventional, million-man military. Once it has reliable nuclear arms, Pyongyang could reduce its spending on other areas of the military and redirect those savings toward the domestic economy. It's possible Kim Jong Un has already begun doing that.

Officially announced budgets have shown increases in funds for the public good, and Kim has adopted as his guiding policy a strategy of simultaneously developing the country's nuclear arsenal and the national economy. Outside estimates indicate the North's GDP has been growing slowly or at least holding steady since he became leader, and there has been visible growth in construction and infrastructure projects, along with the production of consumer goods, over the past five years. The flip side is the harder to quantify loss in revenue from trade and friendly relationships with the outside world due to sanctions aimed at getting Pyongyang to denuclearize.

WATCH: This former defense secretary is terrified of nuclear catastrophe