Ingrown hairs

How can I prevent ingrown hairs from shaving, also how to get rid of them?