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: Thousands Lace Up For U.S. Pond Hockey Championships In Minneapolis

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: 1 Student, Driver Hospitalized After Van Collides With School Bus In New Brighton

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

MORE NEWS: 2 Teenagers Accused In Over A Dozen Metro Area Carjackings

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