It was no surprise that President Trump reiterated his demand that Congress pass funding for a wall on the Mexican border during his State of the Union address. The surprise was his off-script comment that he’d like to see increased legal migration to the United States. Increased legal migration in exchange for a border wall makes both political and economic sense.

Congressional leaders are proposing a deal that would secure $1.4 billion for a border wall—far short of the $5.7 billion President Trump requested. But President Trump’s State of the Union remarks hint that both he and Congressional Democrats can do better than this.

He went off the official script when he said, “Legal immigrants enrich our nation and strengthen our society in countless ways. I want people to come into our country in the largest numbers ever, but they have to come in legally.” His script didn’t include “in the largest numbers ever.” It’s precisely through increased legal migration that he can make a political bargain, better secure the southern border, and improve our economy.

Republican bills that bundled border-wall funding and decreased legal immigration in exchange for a path to legality for people brought to the United States illegally as children, so-called Dreamers, failed to pass even when the Republicans controlled both houses of Congress last year. To get bipartisan support, border-wall funding should be coupled with both a path to legality for Dreamers and increased legal migration.

Increased legal immigration could also enhance the effectiveness of any wall in securing the border. Net migration from Mexico has been negative since the Great Recession, according to the Pew Research Center, but economic immigrants looking for better opportunities still flow north in caravans from other Latin American countries. If more immigration visas were issued for people from these countries, they would all come through legal checkpoints. That would put much less pressure on law enforcement and the border.

Law-enforcement resources would be freed up for real criminals, drug-cartel members, and other people ineligible for visas. In short, more visas would dry up legitimate immigrants’ demand to cross the border illegally and any money for a wall or enforcement would become all the more effective at preventing entry by those who intend harm.

An immigration deal along these lines would also improve our economy.

A path to legality for the Dreamers is an obvious no-brainer. They are already in the United States, not going anywhere, and would become more productive if they were granted legal status. This need not be viewed as amnesty by law-and-order Republicans. Normal criminal law holds children to different standards than adults who break the same laws. Why should a child who violated an immigration law, often without any choice in the matter, not also be held to a different standard?

Trump is right that immigrants “enrich our nation.” Immigration, just like international trade in goods, allows Americans to earn more by specializing in those jobs that we’re most productive at. Like trade, it changes the mix of jobs, not the number of jobs, performed by Americans.

Neither does immigration decrease wages for the vast majority of Americans. To the extent that low-skilled immigration harms anyone, it tends to be natives without a high school degree, but even then the impact is small and only temporary.

Studies on the fiscal impact of immigration are more mixed, but most responsible ones find only mild effects in one direction or the other. To the extent that budgetary impacts are a concern, they could easily be addressed with a modest tariff on immigration visas. President Trump seems to be a fan of tariffs.

The United States has been due for immigration reform for over a decade, but partisan politics has stood in the way. If the president means what he said about increasing legal immigration, a path forward exists. Funding a border wall in exchange for increased legal immigration and a path to legality for Dreamers makes both political and economic sense. Politicians on both sides of the aisle should embrace a deal like this.