JPMorgan profits hit by legal costs