Cardinals' misery ends with 27-13 loss at 49ers