When I was doing contract work and a manager asked to join in meetings, I would say "I can come for xx minutes - 15, 30, whatever seemed reasonable to me based on the topic. If the discussion was productive, I might stay longer. Most of the time, the discussion was pointless and I'd leave. The worst was standing meetings (recurred every week at the same time). The agenda hardly ever changed and not much of anything ever got done, other than discussing the same list of problems every week.
Long team meetings are a total time suck.
Edit: you could just leave after it gets stupid, and if asked why, tell them you had another meeting! If you just leave, how do they know you're not having a "bathroom emergency"? Sounds like a good excuse to me. And if you do it enough that they press you on it, it seems reasonable to say "I didn't have anything more to contribute to the discussion so I thought my time was better used working on my current project." Seems a manager would be hard-pressed to argue with that.