DALLAS (AP) — President Barack Obama says protesters who attack police officers are doing a disservice to their cause.

Obama said in Madrid after meeting with Spain’s acting prime minister that one of the great things about America is that individuals and groups can protest and speak truth to power. He says the process is sometimes messy and controversial, but the ability to engage in free speech has improved America.

READ MORE: Minnesota Weather: Severe Thunderstorm Watch Issued For Parts Of Minnesota, Wisconsin

Obama also cautions that if protesters paint police with a broad brush, they could lose allies for their cause. At the same time, he says that when police organizations acknowledge there is a problem stemming from bias, it will contribute to solutions.

READ MORE: Police Report Rash Of Car Thefts Across West Twin Cities Metro Area

Obama is cutting his first visit to Spain a day short because of a series of deadly shootings in the U.S.

MORE NEWS: 'Pure Mask Sweatiness': Students Face Masking Up Again For In-Person Learning

(© Copyright 2016 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.)