WASHINGTON (AP) — Seeking a bipartisan compromise to avoid a government shutdown, President Donald Trump suggested Tuesday that an immigration deal could be reached in two phases — first by addressing young immigrants and border security with what he called a “bill of love,” then by making comprehensive changes that have long eluded Congress.

Trump presided over a lengthy meeting with Republican and Democratic lawmakers seeking a solution for hundreds of thousands of young people who were brought to the U.S. as children and living here illegally. Trump last year ended the Obama-era Deferred Action for Childhood Arrivals program, which shielded more than 700,000 people from deportation and gave them the right to work legally. He gave Congress until March to find a fix.

The president, congressional Republicans and Democrats expressed optimism for a deal just 10 days before a government shutdown deadline. Trump said he was willing to be flexible in finding an agreement as Democrats warned that the lives of hundreds of thousands of immigrants hung in the balance.

Trump said he was willing to be flexible in finding an agreement as Democrats warned that the lives of hundreds of thousands of immigrants hung in the balance.

“I think my positions are going to be what the people in this room come up with,” Trump said during a Cabinet Room meeting with a bipartisan group of nearly two dozen lawmakers, adding, “I am very much reliant upon the people in this room.” A group of journalists observed the meandering meeting for an extraordinary length of time — about 55 minutes — that involved Trump seeking input from Democrats and Republicans alike in a freewheeling exchange on the contentious issue.

The White House said after the meeting that lawmakers had agreed to narrow the scope of the negotiations to four areas: border security, family-based “chain migration,” the visa lottery, and the DACA policy, winning nods from Democrats.

“It’s encouraging that the president seems open to a narrow deal protecting the Dreamers,” said Senate Democratic leader Chuck Schumer of New York.

The unusually public meeting laid bare a back-and-forth between the parties more typically confined to closed-door negotiations. At one point, California Sen. Dianne Feinstein, a Democrat, asked Trump if he would support a “clean” DACA bill now with a commitment to pursue a comprehensive immigration overhaul later.

Trump responded, “I would like it … I think a lot of people would like to see that but I think we have to do DACA first.” House Majority Leader Kevin McCarthy, R-Calif., interjected, saying, “Mr. President, you need to be clear though,” that legislation involving the so-called Dreamers would need to include border security.

Trump also suggested bringing back “earmarks,” or money for pet projects requested by lawmakers, as a way to bridge the divide between the two parties. Conservative groups responded that any resumption of earmarks ran the risk of special interests playing a bigger role in government, a notion at odds with Trump’s “drain the swamp” campaign mantra.

On immigration, the president said he would insist on construction of a border security wall as part of an agreement involving young immigrants, but he said Congress could then pursue a comprehensive immigration overhaul in a second phase of talks.

House Republicans said they planned to soon introduce legislation to address border security and the young immigrants. Trump said, “it should be a bill of love.”

WATCH: White House says Trump hasn’t given up on Mexico paying for border wall

Trump’s embrace of a “bill of love” brought to mind his past criticism of former GOP presidential rival Jeb Bush, who said many people come to the U.S. illegally as an “act of love.” Trump’s campaign posted a video at the time with a tagline that read, “Forget love, it’s time to get tough!”

Conservatives quickly sounded alarms about a process that would lead to a comprehensive agreement on immigration, a path that has long been anathema to many rank-and-file Republicans.

“Nothing Michael Wolff could say about @realDonaldTrump has hurt him as much as the DACA lovefest right now,” tweeted conservative commentator Ann Coulter, referencing Trump’s recent portrayal in the book, “Fire and Fury.”

Rep. Mark Meadows, R-N.C., leader of the hard-right House Freedom Caucus, said in a text message after the White House meeting he was “generally” opposed to a two-step process “because history would indicate the second step never happens.” But he later said that if the first steps included the four areas outlined by the White House, “then I could support a two-step process realizing that step one is the only thing that is guaranteed.”

The president appeared to acknowledge the potential political pitfalls of pursuing a more permanent deal, telling the lawmakers, “I’ll take all the heat you want. But you are not that far away from comprehensive immigration reform.”

After the meeting, lawmakers from both parties appeared divided over the basic definition of Trump’s bottom-line demand for a border wall on the southern border.

After the meeting, lawmakers from both parties appeared divided over the basic definition of Trump’s bottom-line demand for a border wall on the southern border.

Democratic House Whip Steny Hoyer of Maryland said his party was opposed to GOP calls for $18 billion in funding to build the wall. “It was clear in the meeting that wall did not mean some structure,” he said of Trump’s remarks, noting the president also mentioned fencing, cameras, and other security measures for the border.

Republicans were adamant that Trump’s call “means the wall,” but that Trump acknowledged it does not need to cover the entire length of the border, because of geographic barriers. Just how many miles of a constructed wall the president would need to sign onto an immigration bill would be subject to negotiation, McCarthy said.

Democrats and Republicans are set to resume negotiations on Wednesday.

The immigration talks pit a president who made the construction of a border wall a central piece of his 2016 campaign against congressional Democrats who have sought to preserve the Obama-era protections for the young immigrants.

The discussions are taking place in the aftermath of Trump’s public blow-up with former campaign and White House adviser Steve Bannon, one of the architects of Trump’s calls for the border wall.

Bannon’s break with Trump has raised concerns among some conservative Republicans that the president might reach an agreement with Democrats on the Dreamers without getting enough in return on border security and significant changes to the immigration system.

Trump as recently as last weekend said he wouldn’t sign legislation addressing DACA unless Congress agreed to an overhaul of the legal immigration system, saying any deal must include an overhaul of the family-based immigration system as well as an end to the diversity visa lottery, which draws immigrants from under-represented parts of a world.

That would be in addition to Trump winning funding for his promised southern border wall and added border security. But in the meeting he indicated a willingness to compromise with Democrats, whose votes are needed in the narrowly divided Senate.

“The president exhibited, I thought, quite a bit of flexibility when the cameras weren’t there in terms of what we do in this phase and the next phase — and an acknowledgment that a lot of things we want to do are going to be part of a comprehensive bill but not now,” said Sen. Jeff Flake, R-Ariz., one of the attendees.

Associated Press writers Andrew Taylor, Catherine Lucey, Zeke Miller and Darlene Superville contributed to this report.