Don't do it without at least trying for derm.
You never know, you could match. I didn't consider myself a strong applicant after reading the horror stories online about walk on water applicants going unmatched. I still got lots of interviews and matched well.
If you're set on doing a residency instead of derm research fellowship, then do IM as your backup. At least you'll have tried!
Doing IM residency first might help you at a select few programs, but it will also disqualify you from consideration from programs that don't have a lot of extra funding. You only get a certain number of years as a government funded resident, depending on your specialty... then the program has to want you bad enough to foot the bill. Unlikely to happen unless you achieve something amazing during IM residency.