Confusing Number II

A confusing number is a positive integer that becomes a different valid integer when its digits are rotated 180 degrees. The valid digit mappings are 0 -> 0, 1 -> 1, 6 -> 9, 8 -> 8, and 9 -> 6; any other digit makes the number invalid after rotation. Given N, count confusing numbers in the inclusive range 1..N.

Examples
Input: 20
Output: 6
Hints

Confusing Number II

A confusing number is a positive integer that becomes a different valid integer when its digits are rotated 180 degrees. The valid digit mappings are `0 -> 0`, `1 -> 1`, `6 -> 9`, `8 -> 8`, and `9 -> 6`; any other digit makes the number invalid after rotation. Given `N`, count confusing numbers in the inclusive range `1..N`.